Documentation
¶
Overview ¶
Package ds contains data structures
Index ¶
- type List
- func (l List[T]) All(ok func(T) bool) bool
- func (l List[T]) AllIndexFunc(itemFn func(T) bool) List[int]
- func (l List[T]) AllIndexed(ok func(int, T) bool) bool
- func (l List[T]) Any(ok func(T) bool) bool
- func (l List[T]) AnyIndexed(ok func(int, T) bool) bool
- func (l List[T]) Apply(task func(T) T) List[T]
- func (l List[T]) Cap() int
- func (l List[T]) Copy() List[T]
- func (l List[T]) CountFunc(ok func(T) bool) int
- func (l List[T]) Filter(keep func(T) bool) List[T]
- func (l List[T]) FilterIndexed(keep func(int, T) bool) List[T]
- func (l List[T]) Get(index int) Option[T]
- func (l List[T]) GetFuncOrDefault(itemFn func(T) bool, defaultValue T) T
- func (l List[T]) GetRandom() Option[T]
- func (l List[T]) IndexFunc(itemFn func(T) bool) int
- func (l List[T]) IsEmpty() bool
- func (l List[T]) Last(rank int) Option[T]
- func (l List[T]) LastIndex() int
- func (l List[T]) Len() int
- func (l List[T]) MapList(indexes []int) List[T]
- func (l List[T]) MustGetRandom() T
- func (l List[T]) MustLast(rank int) T
- func (l List[T]) NotAny(ok func(T) bool) bool
- func (l List[T]) NotAnyIndexed(ok func(int, T) bool) bool
- func (l List[T]) NotEmpty() bool
- func (l List[T]) Reduce(initial T, reducer func(T, T) T) T
- func (l List[T]) RemoveAllFunc(itemFn func(T) bool) List[T]
- func (l List[T]) RemoveFunc(itemFn func(T) bool) (List[T], bool)
- func (l List[T]) Shuffle()
- func (l List[T]) ToAny() List[any]
- type Map
- func (m Map[K, V]) Clear()
- func (m Map[K, V]) Copy() Map[K, V]
- func (m Map[K, V]) Delete(key K)
- func (m Map[K, V]) Entries() List[Tuple2[K, V]]
- func (m Map[K, V]) Filter(keep func(K, V) bool) Map[K, V]
- func (m Map[K, V]) Get(key K) Option[V]
- func (m Map[K, V]) GetOrDefault(key K, defaultValue V) V
- func (m Map[K, V]) HasKey(key K) bool
- func (m Map[K, V]) HasKeyFunc(test func(K) bool) bool
- func (m Map[K, V]) HasValueFunc(test func(V) bool) bool
- func (m Map[K, V]) IsEmpty() bool
- func (m Map[K, V]) Keys() List[K]
- func (m Map[K, V]) KeysIter() iter.Seq[K]
- func (m Map[K, V]) Len() int
- func (m Map[K, V]) NoKey(key K) bool
- func (m Map[K, V]) NoKeyFunc(test func(K) bool) bool
- func (m Map[K, V]) NoValueFunc(test func(V) bool) bool
- func (m Map[K, V]) NotEmpty() bool
- func (m Map[K, V]) SetDefault(key K, defaultValue V)
- func (m Map[K, V]) SortedEntriesFunc(sortFn func(Tuple2[K, V], Tuple2[K, V]) int) List[Tuple2[K, V]]
- func (m Map[K, V]) SortedKeysFunc(sortFn func(K, K) int) List[K]
- func (m Map[K, V]) SortedValuesFunc(sortFn func(V, V) int) List[V]
- func (m Map[K, V]) String() string
- func (m Map[K, V]) Unzip() (List[K], List[V])
- func (m Map[K, V]) Update(newMap Map[K, V])
- func (m Map[K, V]) Values() List[V]
- func (m Map[K, V]) ValuesIter() iter.Seq[V]
- type NumList
- type Option
- type Pair
- type Quad
- type Queue
- func (q *Queue[T]) Clear()
- func (q *Queue[T]) Copy() *Queue[T]
- func (q *Queue[T]) Dequeue() Option[T]
- func (q *Queue[T]) Enqueue(item T)
- func (q *Queue[T]) Front() Option[T]
- func (q *Queue[T]) IsEmpty() bool
- func (q *Queue[T]) Items() List[T]
- func (q *Queue[T]) Len() int
- func (q *Queue[T]) MustDequeue() T
- func (q *Queue[T]) MustFront() T
- func (q *Queue[T]) NotEmpty() bool
- func (q *Queue[T]) String() string
- type Range
- func (r Range[T]) Copy() Range[T]
- func (r Range[T]) Has(item T) bool
- func (r Range[T]) IsReversed() bool
- func (r Range[T]) Len() int
- func (r Range[T]) Limits() (start, end T)
- func (r Range[T]) Product() T
- func (r Range[T]) String() string
- func (r Range[T]) Sum() T
- func (r Range[T]) ToList() List[T]
- func (r Range[T]) ToSlice() []T
- type Result
- type Set
- func (s Set[T]) Add(items ...T)
- func (s Set[T]) Clear()
- func (s Set[T]) Copy() Set[T]
- func (s Set[T]) Delete(item T)
- func (s Set[T]) Difference(s2 Set[T]) Set[T]
- func (s Set[T]) Has(item T) bool
- func (s Set[T]) HasDifference(s2 Set[T]) bool
- func (s Set[T]) HasIntersection(s2 Set[T]) bool
- func (s Set[T]) HasNo(item T) bool
- func (s Set[T]) HasNoDifference(s2 Set[T]) bool
- func (s Set[T]) HasNoIntersection(s2 Set[T]) bool
- func (s Set[T]) Intersection(s2 Set[T]) Set[T]
- func (s Set[T]) IsEmpty() bool
- func (s Set[T]) Items() List[T]
- func (s Set[T]) Len() int
- func (s Set[T]) NotEmpty() bool
- func (s Set[T]) String() string
- func (s Set[T]) Union(s2 Set[T]) Set[T]
- type Stack
- func (s *Stack[T]) Clear()
- func (s *Stack[T]) Copy() *Stack[T]
- func (s *Stack[T]) IsEmpty() bool
- func (s *Stack[T]) Items() List[T]
- func (s *Stack[T]) Len() int
- func (s *Stack[T]) MustPop() T
- func (s *Stack[T]) MustTop() T
- func (s *Stack[T]) NotEmpty() bool
- func (s *Stack[T]) Pop() Option[T]
- func (s *Stack[T]) Push(item T)
- func (s *Stack[T]) String() string
- func (s *Stack[T]) Top() Option[T]
- type Triple
- type Tuple2
- type Tuple3
- type Tuple4
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type List ¶
type List[T any] []T
func (List[T]) AllIndexFunc ¶
AllIndexFunc returns all indexes of item in the List, using the item function
func (List[T]) AllIndexed ¶
AllIndexed checks if all List item passes the ok function: (index, item)
func (List[T]) AnyIndexed ¶
AnyIndexed checks if any List item passes the ok function: (index, item)
func (List[T]) FilterIndexed ¶
FilterIndexed filters the List by only keeping items that pass the keep function: (index, item)
func (List[T]) GetFuncOrDefault ¶
GetFuncOrDefault returns the first item that passes the item function, or returns the default value
func (List[T]) GetRandom ¶
GetRandom gets a random item from List, and a flag which indicates if it is valid
func (List[T]) IndexFunc ¶
IndexFunc returns the index of item (or -1 if not in List), using the item function
func (List[T]) Last ¶
Last returns the nth item from the back of the List (starts at 1), and a flag which indicates if it is valid
func (List[T]) MapList ¶
MapList maps the indexes to List items. Can have zero values for invalid indexes
func (List[T]) MustGetRandom ¶
func (l List[T]) MustGetRandom() T
MustGetRandom gets a random item from List, and panics if list is empty
func (List[T]) MustLast ¶
MustLast returns the nth item from the back of the List (starts at 1). Panics if rank is not 1 <= rank <= N, where N = length of List.
func (List[T]) NotAnyIndexed ¶
NotAnyIndexed checks if no List item passes the ok function: (index, item)
func (List[T]) Reduce ¶
func (l List[T]) Reduce(initial T, reducer func(T, T) T) T
Reduce applies the reducer to each item to get the final result. The reducer function has the signature (result, item) => result
func (List[T]) RemoveAllFunc ¶
RemoveAllFunc removes all items from List that passes the item function
func (List[T]) RemoveFunc ¶
RemoveFunc removes the first item from List that passes the item function
type Map ¶
type Map[K comparable, V any] map[K]V
func ZipMap ¶
func ZipMap[K comparable, V any](keys List[K], values List[V]) Map[K, V]
ZipMap creates a new Map by zipping the keys and values
func (Map[K, V]) GetOrDefault ¶
func (m Map[K, V]) GetOrDefault(key K, defaultValue V) V
GetOrDefault gets the value associated with key if it exists, otherwise returns the default value
func (Map[K, V]) HasKeyFunc ¶
HasKeyFunc checks if any Map key passes the test function
func (Map[K, V]) HasValueFunc ¶
HasValueFunc checks if any Map value passes the test function
func (Map[K, V]) NoValueFunc ¶
NoValueFunc checks that no Map value passes the test function
func (Map[K, V]) SetDefault ¶
func (m Map[K, V]) SetDefault(key K, defaultValue V)
SetDefault assigns default value to key, if key is not in Map
func (Map[K, V]) SortedEntriesFunc ¶
func (m Map[K, V]) SortedEntriesFunc(sortFn func(Tuple2[K, V], Tuple2[K, V]) int) List[Tuple2[K, V]]
SortedEntriesFunc returns the Map entries in sorted order, using SortFn
func (Map[K, V]) SortedKeysFunc ¶
SortedKeysFunc returns the Map keys in sorted order, using sortFn
func (Map[K, V]) SortedValuesFunc ¶
SortedValuesFunc returns the Map values in sorted order, using SortFn
func (Map[K, V]) Unzip ¶
Unzip returns the list of Map keys and values, where order of keys is same as corresponding values
func (Map[K, V]) Update ¶
Update adds the entries of new Map to current Map. If there are overlapping keys, new Map entries overwrite the old Map entries.
func (Map[K, V]) ValuesIter ¶
ValuesIter returns an iterator for the Map values
type NumList ¶
type Option ¶
type Option[T any] struct { // contains filtered or unexported fields }
type Queue ¶
type Queue[T any] struct { // contains filtered or unexported fields }
func NewQueueFrom ¶
NewQueueFrom creates a new queue from list of items
func (*Queue[T]) Dequeue ¶
Dequeue returns an Option that contains the front item, and removes it from the queue. If the queue is empty, the Option contains nil
func (*Queue[T]) Enqueue ¶
func (q *Queue[T]) Enqueue(item T)
Enqueue adds an item to the back of the queue
func (*Queue[T]) Front ¶
Front returns an Option that contains the front item. If the queue is empty, the Option contains nil
func (*Queue[T]) MustDequeue ¶
func (q *Queue[T]) MustDequeue() T
MustDequeue returns the front item and removes it from the queue, and panics if the queue is empty
type Range ¶
Range represents a range of Integers from [start, end)
func NewInclusiveRange ¶
NewInclusiveRange creates a new Range from [first, last]
func (Range[T]) IsReversed ¶
IsReversed checks if the Range is reversed
func (Range[T]) Limits ¶
func (r Range[T]) Limits() (start, end T)
Limits returns the start, end limits of the Range
type Result ¶
type Result[T any] struct { // contains filtered or unexported fields }
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
func NewSetFrom ¶
func NewSetFrom[T comparable](items []T) Set[T]
NewSetFrom creates a new Set from given items
func NewSetFunc ¶
func NewSetFunc[T any, K comparable](items []T, keyFn func(T) K) Set[K]
NewSetFunc creates a new Set from given items, using the keyFn
func (Set[T]) Difference ¶
Difference computes the difference of two Sets
func (Set[T]) HasDifference ¶
HasDifference checks if two Sets have a non-empty difference
func (Set[T]) HasIntersection ¶
HasIntersection checks if two Sets have a non-empty intersection
func (Set[T]) HasNoDifference ¶
HasNoDifference checks if two Sets have an empty difference
func (Set[T]) HasNoIntersection ¶
HasNoIntersection checks if two Sets have an empty intersection
func (Set[T]) Intersection ¶
Intersection computes the intersection of two Sets
type Stack ¶
type Stack[T any] struct { // contains filtered or unexported fields }
func NewStackFrom ¶
NewStackFrom creates a new stack from list of items (last item = stack top)
func (*Stack[T]) MustPop ¶
func (s *Stack[T]) MustPop() T
MustPop returns the top item and removes it from the stack, and panics if the stack is empty
func (*Stack[T]) MustTop ¶
func (s *Stack[T]) MustTop() T
MustTop returns the top item, and panics if the stack is empty
func (*Stack[T]) Pop ¶
Pop returns an Option that contains the top item and removes it from the stack. If the stack is empty, the Option contains nil
type Tuple3 ¶
type Tuple3[A, B, C any] struct { V1 A V2 B V3 C }
Tuple3 is a tuple with three types