Documentation ¶
Index ¶
- Constants
- Variables
- func Abs[T SignedNum](a T) T
- func Add2[T Num](p, q [2]T) [2]T
- func Add3[T Num](p, q [3]T) [3]T
- func Append[T any](xs *[]T, el ...T)
- func AssertEqual[E comparable](t *testing.T, got, want E)
- func AssertSlicesEqual[E comparable](t *testing.T, got, want []E)
- func CaptureStdout(f func()) []byte
- func Colinear(a, b, c [2]float64) bool
- func Det22[T Num, E ~[2]T](a, b E) T
- func Det22Rat(a, b [2]*big.Rat) *big.Rat
- func Det32[T Num, E ~[2]T](a, b, c E) T
- func Dist2[T SignedNum](a, b [2]T) T
- func DistL1Rat(a, b [2]*big.Rat) *big.Rat
- func EdgesOf[T comparable](g map[T]map[T]int) map[[2]T]int
- func Filter[E any](xs []E, pred func(E) bool) []E
- func FloydWarshallUnitEdges(g [][]int) (dist [][]int)
- func Freq[E comparable](xs []E) map[E]int
- func Gcd(a, b int) int
- func GlobalMinCut(mat [][]int) (int, []int)
- func Greater[T Ordered](p, q T) bool
- func Greater2[T Ordered](p, q [2]T) bool
- func Greater3[T Ordered](a, b [3]T) bool
- func IntersectCuboids[T Ordered](xs, ys [][2]T) [][2]T
- func IntersectItvs[T Ordered](x, y [2]T) [2]T
- func IsBetween(a, b, c [2]*big.Rat) bool
- func IsDigit[T rune | byte](ch T) bool
- func IsEmptyItv[T Ordered](a [2]T) bool
- func Last[E any](xs []E) E
- func Lcm(xs ...int) int
- func Less2[T Ordered](a, b [2]T) bool
- func Less3[T Ordered](a, b [3]T) bool
- func LessOrEqual2[T Ordered](a, b [2]T) bool
- func Map[T, S any](f func(T) S, xs []T) []S
- func MatrixOfAdjList(g AdjList) [][]int
- func MaxIdx[T Ordered](xs []T) int
- func MergeItvs[T Ordered](itvs [][2]T) [][2]T
- func MkNumsUpto[E Num](n int) []E
- func MkSlice2[E any](rows, cols int) [][]E
- func MkSlice2Filled[E any](rows, cols int, t E) [][]E
- func MkSlice3[E any](rows, cols, height int) [][][]E
- func MkSlice3Filled[E any](rows, cols, height int, e E) [][][]E
- func MkSliceFilled[E any](rows int, t E) []E
- func Mod(a, b int) int
- func PolygonArea(pts [][2]int) int
- func PopBack[E any](x *[]E) E
- func PopFront[E any](x *[]E) E
- func PrefixSums[T Num](xs []T) []T
- func PrefixSumsFunc[T Num](f func(int) T, n int) []T
- func PrintlnVect2s(vs []Vect2)
- func Prod[T Num](xs []T) T
- func PushBack[E any](x *[]E, e E)
- func PushFront[E any](x *[]E, e E)
- func QuadraticSolve(a, b, c float64) (float64, float64, bool)
- func ReadByteSlices() [][]byte
- func ReadByteSlicesFromScanner(sc *bufio.Scanner) [][]byte
- func ReadLines() []string
- func ReadLinesFromFile(fileName string) []string
- func ReadStringsFromScanner(sc *bufio.Scanner) []string
- func ReadTextFromScanner(sc *bufio.Scanner) string
- func Reverse[E any](x []E)
- func ScanFloat(sc *bufio.Scanner) float64
- func ScanInt(sc *bufio.Scanner) int
- func ScanText(sc *bufio.Scanner) string
- func SecantSearch(f func(float64) float64, a, b, precision float64) float64
- func SetMax[T Ordered](a *T, b T)
- func SetMin[T Ordered](a *T, b T)
- func SetStdin(fName string) *os.File
- func Shuffle[T any](xs []T)
- func Sign[T SignedNum](a T) int
- func SlicesEqual[E comparable](s1, s2 []E) bool
- func SortLess2[T Ordered](s [][2]int)
- func SortSliceDecr[T Ordered](xs []T)
- func SortSliceFunc[E any, T Ordered](xs []E, f func(E) T)
- func SortSliceLessFunc[E any](xs []E, less func(a, b E) bool)
- func StringOfList(l *list.List) string
- func StringOfPointerSlice[T any](l []*T) string
- func Sum[T Num](xs []T) T
- func SumOverMap[T comparable, E Num](m map[T]E) E
- func SurfaceOfCuboid3(width, height, depth int) int
- func Swap[T any](a [2]T) [2]T
- func TernarySearch(f func(float64) float64, a, b, precision float64) float64
- func TransposeStrings(xs []string) []string
- type AdjList
- type AdjMap
- type Bits
- type Heap
- type Integer
- type MapGraph
- func (g MapGraph[T]) Add(u, v int, weight T)
- func (g MapGraph[T]) AddBoth(u, v int, weight T)
- func (g MapGraph[T]) AddBothNoChecks(u, v int, weight T)
- func (g MapGraph[T]) AddNoChecks(u, v int, weight T)
- func (g MapGraph[T]) Delete(u, v int)
- func (g MapGraph[T]) DeleteBoth(u, v int)
- func (g MapGraph[T]) HasEdge(u, v int) bool
- func (g MapGraph[T]) HasEdgeNoChecks(u, v int) bool
- func (g MapGraph[T]) LongestPathsAcyclicNP(src int, MAX T) []T
- func (g MapGraph[T]) ShortestPathNP(src, tgt int, MAX T) T
- func (g MapGraph[T]) TopoSort() []int
- func (g MapGraph[T]) Weight(u, v int) T
- type Num
- type Ordered
- type PQInt
- func NewMaxPrioQ[T Ordered](prio []T, num ...int) *PQInt[int]
- func NewMaxPrioQG[T Ordered, U Integer](prio []T, num ...int) *PQInt[U]
- func NewMinCostQ[T Ordered](cost []T, num ...int) *PQInt[int]
- func NewMinCostQG[T Ordered, U Integer](cost []T, num ...int) *PQInt[U]
- func NewPQInt[T Integer](less func(a, b T) bool, num ...int) *PQInt[T]
- type PQItem
- type PQueue
- type Pair
- type RLine
- type SignedNum
- type UnionFind
- type Vect2
- func (v Vect2) Add(w [2]float64) Vect2
- func (v Vect2) Angle() float64
- func (p Vect2) AngleAt(q, r [2]float64) float64
- func (v Vect2) AngleBetween(w [2]float64) float64
- func (v Vect2) Dist(w [2]float64) float64
- func (v Vect2) DistSquared(q [2]float64) float64
- func (v Vect2) Dot(w [2]float64) float64
- func (v Vect2) Mag() float64
- func (v Vect2) MagSquared() float64
- func (v Vect2) Normal() Vect2
- func (v Vect2) Normalize() Vect2
- func (a Vect2) Orientation(b, c [2]float64) int
- func (v Vect2) Rotate(θ float64) Vect2
- func (p Vect2) RotateAround(q [2]float64, θ float64) Vect2
- func (v Vect2) Scale(λ float64) Vect2
- func (v Vect2) String() string
- func (v Vect2) Subtract(w [2]float64) Vect2
- func (p Vect2) To(q Vect2) Vect2
- func (v Vect2) X() float64
- func (v Vect2) Y() float64
Constants ¶
const EPSILON = 1e-12
Variables ¶
var AocFunMap map[int][]func()
Functions ¶
func AssertEqual ¶
func AssertEqual[E comparable](t *testing.T, got, want E)
func AssertSlicesEqual ¶
func AssertSlicesEqual[E comparable](t *testing.T, got, want []E)
func CaptureStdout ¶
func CaptureStdout(f func()) []byte
func EdgesOf ¶
func EdgesOf[T comparable](g map[T]map[T]int) map[[2]T]int
func FloydWarshallUnitEdges ¶
func Freq ¶
func Freq[E comparable](xs []E) map[E]int
func GlobalMinCut ¶
func IntersectCuboids ¶
func IntersectCuboids[T Ordered](xs, ys [][2]T) [][2]T
func IntersectItvs ¶
func IntersectItvs[T Ordered](x, y [2]T) [2]T
Intersection of two (closed) intervals
func IsBetween ¶
IsBetween checks whether point b is between a and c It assumes all three points are on one line
func IsEmptyItv ¶
IsEmpty returns true if the interval is empty
func LessOrEqual2 ¶
func MatrixOfAdjList ¶
func MkNumsUpto ¶
func MkSlice2Filled ¶
func MkSlice3Filled ¶
func MkSliceFilled ¶
func PolygonArea ¶
func PrefixSums ¶
func PrefixSums[T Num](xs []T) []T
func PrefixSumsFunc ¶
func PrintlnVect2s ¶
func PrintlnVect2s(vs []Vect2)
func ReadByteSlices ¶
func ReadByteSlices() [][]byte
func ReadLinesFromFile ¶
func ReadStringsFromScanner ¶
func ReadTextFromScanner ¶
func SlicesEqual ¶
func SlicesEqual[E comparable](s1, s2 []E) bool
func SortSliceDecr ¶
func SortSliceDecr[T Ordered](xs []T)
func SortSliceFunc ¶
func SortSliceLessFunc ¶
func StringOfList ¶
func StringOfPointerSlice ¶
func SumOverMap ¶
func SumOverMap[T comparable, E Num](m map[T]E) E
func SurfaceOfCuboid3 ¶
func TransposeStrings ¶
Types ¶
type Heap ¶
type Heap[T any] struct { // contains filtered or unexported fields }
func NewCostFunHeap ¶
func NewMaxHeap ¶
func NewMinHeap ¶
func (*Heap[T]) Fix ¶
Fix re-establishes the heap ordering after the element at index i has changed its value. Changing the value of the element at index i and then calling Fix is equivalent to, but less expensive than, calling h.Remove(i) followed by a Push of the new value. The complexity is O(log n) where n = h.Len().
func (*Heap[T]) Init ¶
func (h *Heap[T]) Init()
Init establishes the heap invariants required by the other routines in this package. Init is idempotent with respect to the heap invariants and may be called whenever the heap invariants may have been invalidated. The complexity is O(n) where n = h.Len().
func (*Heap[T]) Pop ¶
func (h *Heap[T]) Pop() T
Pop removes and returns the minimum element (according to lessFun) from the heap. The complexity is O(log n) where n = h.Len(). Pop is equivalent to h.Remove(0).
func (*Heap[T]) Push ¶
func (h *Heap[T]) Push(x T)
Push pushes the element x onto the heap. The complexity is O(log n) where n = h.Len().
type Integer ¶
type Integer interface { constraints.Integer }
type MapGraph ¶
func MkMapGraph ¶
func (MapGraph[T]) Add ¶
Add inserts a directed edge from v to w with weight c. It overwrites the previous weight if this edge already exists.
func (MapGraph[T]) AddBoth ¶
AddBoth inserts edges with weigth c between v and w. It overwrites the previous weights if these edges already exist.
func (MapGraph[T]) AddBothNoChecks ¶
func (MapGraph[T]) AddNoChecks ¶
func (MapGraph[T]) DeleteBoth ¶
DeleteBoth removes all edges between v and w.
func (MapGraph[T]) HasEdgeNoChecks ¶
func (MapGraph[T]) LongestPathsAcyclicNP ¶
func (MapGraph[T]) ShortestPathNP ¶
type Num ¶
type Num interface { constraints.Integer | constraints.Float }
type Ordered ¶
type Ordered interface { constraints.Integer | constraints.Float | ~string }
Ordered represents the set of types for which the '<' operator work.
type PQInt ¶
type SignedNum ¶
type SignedNum interface { constraints.Signed | constraints.Float }
type UnionFind ¶
type UnionFind struct { // Union-find data structure with size for balancing Parent []int Size []int }
https://www.cs.princeton.edu/~rs/AlgsDS07/01UnionFind.pdf Could also define a Union-Find by "rank"="depth" Also called "Disjoint Set"
func NewUnionFind ¶
type Vect2 ¶
type Vect2 [2]float64
func Vect2DOfPolar ¶
func (Vect2) AngleBetween ¶
AngleBetween returns angle between vectors v and w at origin
func (Vect2) DistSquared ¶
func (Vect2) MagSquared ¶
func (Vect2) Orientation ¶
func (Vect2) RotateAround ¶
RotateAround rotates point q around point p by θ