Documentation ¶
Overview ¶
Package aocutils is a collection of utilities meant for helping with advent of code. Might be otherwise useful.
Index ¶
- func Abs[T constraints.Signed | constraints.Float](a T) T
- func Delta[T constraints.Integer | constraints.Float](a, b T) T
- func MapKeys[T comparable, Y any](m map[T]Y) []T
- func Max[T constraints.Ordered](t ...T) T
- func Min[T constraints.Ordered](t ...T) T
- func SliceMap[T any](vals []T, f func(T) T) []T
- func SliceMapMutate[T1 any, T2 any](vals []T1, f func(T1) T2) []T2
- func SliceMapNoModify[T any](vals []T, f func(T) T) []T
- type Set
- type Stack
- func (s *Stack[T]) Clone() *Stack[T]
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) Peek(i int) T
- func (s *Stack[T]) Poke(i int, t ...T) *Stack[T]
- func (s *Stack[T]) Pop() T
- func (s *Stack[T]) PopN(n int) []T
- func (s *Stack[T]) Push(t ...T) *Stack[T]
- func (s *Stack[T]) Set(i int, t T) *Stack[T]
- func (s *Stack[T]) SetVals(vals []T) *Stack[T]
- func (s *Stack[T]) Shift() T
- func (s *Stack[T]) ShiftN(n int) []T
- func (s *Stack[T]) Unshift(t ...T) *Stack[T]
- func (s *Stack[T]) Vals() []T
- type Window
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Abs ¶
func Abs[T constraints.Signed | constraints.Float](a T) T
func Delta ¶
func Delta[T constraints.Integer | constraints.Float](a, b T) T
func MapKeys ¶
func MapKeys[T comparable, Y any](m map[T]Y) []T
func Max ¶
func Max[T constraints.Ordered](t ...T) T
func Min ¶
func Min[T constraints.Ordered](t ...T) T
func SliceMap ¶
func SliceMap[T any](vals []T, f func(T) T) []T
SliceMap - apply a function f to all elements of slice vals, returns the resulting slice.
func SliceMapMutate ¶
func SliceMapNoModify ¶
func SliceMapNoModify[T any](vals []T, f func(T) T) []T
SliceMapNoModify - like SliceMap but does not modify the vals slice.
Types ¶
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set is a trivial set implementation based on maps.
func MakeSet ¶
func MakeSet[T comparable](data []T) *Set[T]
MakeSet - factory method. Returns a set containing the data.
func (*Set[T]) UnorderedSlice ¶
func (s *Set[T]) UnorderedSlice() []T
UnorderedSlice returns an unordered slice containing the elements in the set.
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
Stack implements a stack using generics.
func (*Stack[T]) Peek ¶
Peek gives us the value at index i and returns it. If index i does not exist it returns the zero value of type T. negatives count from the right hand side, so -1 gives the last element.
func (*Stack[T]) Poke ¶
Poke - poke values in at index i. If i is invalid, returns nil. Otherwise inserts t into stack at index i, returning a reference to the stack. Negative indexes count from the right, however -1 will insert one before the last element of the stack. To insert at the end, either use Push() or passive a positive integer equal to the length of the stack.
func (*Stack[T]) Pop ¶
func (s *Stack[T]) Pop() T
Pop - pop the last value from the stack and return it. If the stack is empty, return the zero value of T
func (*Stack[T]) PopN ¶
PopN - pop up to n values off the stack and return them. If there are less values in the stack than n, the length of the return will be the number of values in the stack.
func (*Stack[T]) Push ¶
Push - pushone or more values onto the stack. Returns a reference to the stack.
func (*Stack[T]) Set ¶
Set assigns value t at index i. negative values of i are allowed, counting from right. If i is invalid, return value is nil, otherwise stack is returned.
func (*Stack[T]) SetVals ¶
SetVals sets the values of the internal slice and returns a reference to the stack s. No copy is made, just an assignment.
func (*Stack[T]) Shift ¶
func (s *Stack[T]) Shift() T
Shift removes the front most element from the stack and returns it. If the stack is empty, returns the zero value of type T.
func (*Stack[T]) ShiftN ¶
ShiftN removes up to n elements from the front of the stack and returns them. If n is larger than the size of the internal slice, the length of the return will be smaller than n.
type Window ¶
type Window[T comparable] struct { // contains filtered or unexported fields }
Window is meant for sliding window loops where you want to maintain statistics about how many occurrences of a given value of type T are in a subset of the data.
func NewWindow ¶
func NewWindow[T comparable](data []T) *Window[T]
NewWindow - Factory method for Window. Initializes state with data, returns a Window
func (*Window[T]) Slide ¶
Slide moves the window down. remove is the value being passed out of the window, add is the value passing into the window.
func (*Window[T]) UnorderedSlice ¶
func (w *Window[T]) UnorderedSlice() []T
UnorderedSlice - this returns the data inside the internal map, unordered.