util

package
v0.0.0-...-e3b635e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 13, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Filter

func Filter[T any](ts []T, f func(T) bool) []T

Filter a list, return only elements that return true for the compare method.

func GetMapKeys

func GetMapKeys[K comparable, V any](data map[K]V) []K

func Hamming

func Hamming(a, b string) int

Calculate Hamming distance between two strings. see https://en.wikipedia.org/wiki/Hamming_distance

func Map

func Map[T, U any](ts []T, f func(T) U) []U

Return a list of elements, where the new element is the result of running the passed function.

func ParseInt

func ParseInt(value string) int

Parse an integer, panic if an error happened.

func ReadFile

func ReadFile(input string) ([]string, error)

Read a complete file line by line into memory.

func Sum

func Sum[T Number](ts []T) T

Sum a slice/array of numbers.

func SumOccurrences

func SumOccurrences(data [][]int) map[int]int

Types

type Number

type Number interface {
	constraints.Integer | constraints.Float
}

type Point

type Point struct {
	Row int
	Col int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL