Documentation ¶
Overview ¶
This example demonstrates a priority queue built using the heap interface.
Index ¶
- Variables
- func Abs[X constraints.Integer](x X) X
- func All[X bool](xs ...X) bool
- func AllEq[X comparable](xs ...X) bool
- func AllFunc[X any](f func(x X) bool, xs ...X) bool
- func Any[X bool](xs ...X) bool
- func AnyFunc[X any](f func(x X) bool, xs ...X) bool
- func Area(a Point2d, b Point2d) int64
- func Copy[X any](slice []X) []X
- func Count[X comparable](slice []X, needle X) int
- func Delete[X comparable](slice []X, el X) []X
- func DeleteAt[X any](slice []X, s int) []X
- func DoEachNeighbor[X any](f func(n Point2d) X, c Point2d, ns []Point2d) []X
- func EnclosedAreaWithinPath(path []Point2d) int64
- func EuclidianDistance(a Point2d, b Point2d) float64
- func Filter[X any](filter func(x X) bool, xs []X) []X
- func FilterMap[X any, M any](f func(x X) (M, bool), xs []X) []M
- func Find[X comparable](slice []X, el X) int
- func GCD[X constraints.Integer](a, b X) X
- func Int(x string) int
- func Int64(x string) int64
- func IntFromHex(x string) int
- func LCM[X constraints.Integer](xs ...X) X
- func Last[X any](xs []X) X
- func ManhattenDistance(a Point2d, b Point2d) int64
- func Map[X any, M any](f func(x X) M, xs []X) []M
- func Max[X constraints.Ordered](xs ...X) X
- func MaxWithKey[X any, Y constraints.Ordered](key func(X) Y, xs ...X) X
- func Min[X constraints.Ordered](xs ...X) X
- func Mul[N Number](xs []N) N
- func ParseInt64List(s string) []int64
- func Reduce[X any, A any](reducer func(acc A, x X) A, xs []X, init A) A
- func ReduceReverse[X any, A any](reducer func(acc A, x X) A, xs []X, init A) A
- func Repeat[X any](slice []X, n int) []X
- func RepeatWithSeparator[X any](slice []X, n int, sep X) []X
- func Reverse[X any](slice []X) []X
- func RotateCounterClockwise[X any](slice [][]X) [][]X
- func Sum[N Number](xs []N) N
- func SumFunc[N Number, Y any](f func(acc N, y Y) N, xs []Y) N
- func SumMap[N Number, X any](f func(x X) N, xs []X) N
- func Transpose[X any](slice [][]X) [][]X
- func Zip[X any](xss ...[]X) [][]X
- type Counter
- type Grid2d
- type Hashed
- type Item
- type Number
- type Pair
- type Point2d
- type PriorityQueue
- type Set
- func (s Set[X]) Add(x X)
- func (s Set[X]) Apply(f func(x X) X)
- func (s Set[X]) Contains(x X) bool
- func (s Set[X]) Copy() Set[X]
- func (s Set[X]) Del(x X) (existed bool)
- func (s Set[X]) Difference(other Set[X]) Set[X]
- func (s Set[X]) Extend(xs ...X)
- func (s Set[X]) Intersection(other Set[X]) Set[X]
- func (s Set[X]) IsDisjoint(other Set[X]) bool
- func (s Set[X]) IsSubSet(other Set[X]) bool
- func (s Set[X]) IsSuperSet(other Set[X]) bool
- func (s Set[X]) SymmetricDifference(other Set[X]) Set[X]
- func (s Set[X]) ToSlice() []X
- func (s Set[X]) Union(other Set[X]) Set[X]
- type Triple
Constants ¶
This section is empty.
Variables ¶
var ( Neighbors2d4 = []Point2d{ 0 + 1i, 0 + -1i, 1 + 0i, -1 + 0i, } Neighbors2d8 = []Point2d{ 0 + 1i, 0 + -1i, 1 + 0i, -1 + 0i, 1 + 1i, 1 + -1i, -1 + 1i, -1 + -1i, } )
Functions ¶
func Abs ¶
func Abs[X constraints.Integer](x X) X
func AllEq ¶
func AllEq[X comparable](xs ...X) bool
func Count ¶
func Count[X comparable](slice []X, needle X) int
func Delete ¶
func Delete[X comparable](slice []X, el X) []X
func EnclosedAreaWithinPath ¶
func EuclidianDistance ¶
func Find ¶
func Find[X comparable](slice []X, el X) int
func GCD ¶
func GCD[X constraints.Integer](a, b X) X
func IntFromHex ¶
func LCM ¶
func LCM[X constraints.Integer](xs ...X) X
func ManhattenDistance ¶
func Max ¶
func Max[X constraints.Ordered](xs ...X) X
Min returns the maximum value in xs xs must be non-empty or it'll panic.
func MaxWithKey ¶
func MaxWithKey[X any, Y constraints.Ordered](key func(X) Y, xs ...X) X
func Min ¶
func Min[X constraints.Ordered](xs ...X) X
Min returns the minimum value in xs xs must be non-empty or it'll panic.
func ParseInt64List ¶
func ReduceReverse ¶
func RepeatWithSeparator ¶
func RotateCounterClockwise ¶
func RotateCounterClockwise[X any](slice [][]X) [][]X
Types ¶
type Counter ¶
type Counter[A comparable] map[A]int
func NewCounter ¶
func NewCounter[A comparable](xs []A) Counter[A]
type Grid2d ¶
type Grid2d[X comparable, Y comparable] map[X]Y
func NewGrid2d ¶
func NewGrid2d[X comparable, Y comparable]() Grid2d[X, Y]
func ParseGrid2d ¶
func (Grid2d[X, Y]) FindOrPanic ¶
func (g Grid2d[X, Y]) FindOrPanic(v Y) X
type Item ¶
type Item[X any] struct { Value X // The value of the item; arbitrary. Priority int // The priority of the item in the queue. // contains filtered or unexported fields }
An Item is something we manage in a priority queue.
type Number ¶
type Number interface { constraints.Integer | constraints.Float }
type Pair ¶
Pair is a dead-simple 2-value pair.
func DistinctValueCombinations ¶
func DistinctValueCombinations[X comparable](xs []X) []Pair[X, X]
type Point2d ¶
type Point2d complex128
Point2d is just a very simple wrapper around a complex128 The x, y coordinates are stored in the real and imag parts of the complex number. The complex number is used to easily have comparable types and easily support properties like addition and substraction of points.
func AllNeighborCoords ¶
func NewPoint2d ¶
type PriorityQueue ¶
A PriorityQueue implements heap.Interface and holds Items.
func (PriorityQueue[X]) Len ¶
func (pq PriorityQueue[X]) Len() int
func (PriorityQueue[X]) Less ¶
func (pq PriorityQueue[X]) Less(i, j int) bool
func (*PriorityQueue[X]) Pop ¶
func (pq *PriorityQueue[X]) Pop() any
func (*PriorityQueue[X]) Push ¶
func (pq *PriorityQueue[X]) Push(x any)
func (PriorityQueue[X]) Swap ¶
func (pq PriorityQueue[X]) Swap(i, j int)
type Set ¶
type Set[X comparable] map[X]struct{}
func NewSet ¶
func NewSet[X comparable](xs ...X) Set[X]
func (Set[X]) Difference ¶
Difference returns the elements that are in s, but not in other
func (Set[X]) Intersection ¶
Intersection returns the elemtsn that are common in s and other
func (Set[X]) IsDisjoint ¶
IsDisjoint returns true if no element of s are in other
func (Set[X]) IsSuperSet ¶
IsSuperSet returns wether s is a superset of other
func (Set[X]) SymmetricDifference ¶
SymmetricDifference returns the elements that are either in s or other, but not in both