common

package
v0.0.0-...-2a72056 Latest Latest
Warning

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

Go to latest
Published: Feb 16, 2024 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AllValues

func AllValues[K Hashable, V comparable](c map[K]V, eq any) bool

func Atoc

func Atoc(s string) uint8

func Atof

func Atof(s string) float64

func Atoi

func Atoi(s string) int

func Chunk

func Chunk[T any](list []T, size int) [][]T

func Deref

func Deref[T any](v *T) T

func EuclideanMod

func EuclideanMod[N constraints.Integer](n N, div N) N

func FasterHash

func FasterHash(data any) string

FasterHash takes any object and returns a hash string as fast as possible.

func Filter

func Filter[T any](list []T, fn func(a T) bool) []T

func FindQuadraticCoefficients

func FindQuadraticCoefficients[N Number](y0, y1, y2 N) (N, N, N)

func GCD

func GCD(a, b int) int

GCD returns the greatest common divisor of the integers.

func HashedMemo

func HashedMemo[In any, Out any](
	f func(a In) Out,
	hashFn *func(data any) string,
	cache *map[string]Out,
) func(a In) Out

HashedMemo is a generic memoization function that hashes an incomparable argument.

func Hexi

func Hexi(s string) int

func In

func In(haystack string, chars string) bool

In is faster than strings.ContainsAny().

func LCM

func LCM(integers ...int) int

LCM returns the least common multiple of the integers.

func Manhattan

func Manhattan[N Number](x1 N, y1 N, x2 N, y2 N) N

func Map

func Map[T, R any](list []T, fn func(a T) R) []R

func Map2

func Map2[T, R any](list []T, fn func(a T, i int) R) []R

func Memo

func Memo[In comparable, Out any](
	f func(a In) Out,
	cache *map[In]Out,
) func(a In) Out

Memo is a generic memoization function that accepts 1 comparable argument.

func NonZero

func NonZero(i int) int

func Octile

func Octile[N Number](x1 N, y1 N, x2 N, y2 N) N

func PicksInterior

func PicksInterior[N Number](area N, boundary N) N

func Product

func Product[N Number](collection []N) N

func Ptr

func Ptr[T any](v T) *T

func Pythagoras

func Pythagoras[N Number](x1 N, y1 N, x2 N, y2 N) N

func Reset

func Reset[T any](c *[]T)

Reset resets the slice to be empty but keeps the capacity.

func Shoelace

func Shoelace[N Number](points []Point2D[N]) float64

func SolveQuadratic

func SolveQuadratic[N Number](a, b, c, x N) N

func Sqrt

func Sqrt[N Number](x N) (z N)

func Sum

func Sum[N Number](collection []N) N

Types

type BucketQueue

type BucketQueue[V any] struct {
	Buckets []*deque.Deque[V]
	// contains filtered or unexported fields
}

func NewBucketQueue

func NewBucketQueue[V any](numBuckets int, bucketCapacity int) *BucketQueue[V]

func (*BucketQueue[V]) Pop

func (q *BucketQueue[V]) Pop() (V, int)

func (*BucketQueue[V]) Push

func (q *BucketQueue[V]) Push(prio int, v V)

func (*BucketQueue[V]) Size

func (q *BucketQueue[V]) Size() int

type Hashable

type Hashable interface {
	~int | ~int8 | ~int16 | ~int32 | ~int64 |
		~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64 | ~uintptr |
		~float32 | ~float64 |
		~string
}

type Number

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

type Point2D

type Point2D[N Number] struct {
	X, Y N
}

type Queue

type Queue[V any] interface {
	Push(V)
	Pop() V
	Size() int
}

type SearchResult

type SearchResult[T any, W Number] struct {
	Best         *T
	BestWeight   W
	BestPath     []*T
	Paths        int
	Milliseconds int64
	Iterations   int
}

func BucketSearch

func BucketSearch[T any, H comparable, W Number](
	root *T,

	branchFn func(branch *T) []*T,

	predicateFn func(branch *T) bool,

	hashFn func(branch *T) H,

	weightFn func(branch *T, parentWeight W) W,

	heuristicFn func(branch *T) W,

	priorityScale int,

	returnFirst bool,

	maximize bool,
) *SearchResult[T, W]

func IterativeSearch

func IterativeSearch[T any, H comparable, W Number](
	root *T,

	branchFn func(branch *T) []*T,

	predicateFn func(branch *T) bool,

	hashFn func(branch *T) H,

	weightFn func(branch *T, parentWeight W) W,

	heuristicFn func(branch *T) W,

	beamWidth int,

	returnFirst bool,

	maximize bool,
) *SearchResult[T, W]

Jump to

Keyboard shortcuts

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