import "github.com/chen3feng/stl4go"
Package stl4go is a generic container and algorithm library for go.
- func AllOf[T any](a []T, pred func(T) bool) bool
- func AnyOf[T any](a []T, pred func(T) bool) bool
- func Average[T Numeric](a []T) T
- func AverageAs[R, T Numeric](a []T) R
- func BinarySearch[T Ordered](a []T, value T) (index int, ok bool)
- func BinarySearchFunc[T any](a []T, value T, less LessFn[T]) (index int, ok bool)
- func Compare[E Ordered](a, b []E) int
- func Copy[T any](a []T) []T
- func CopyTo[T any](a []T, to []T) []T
- func Count[T comparable](a []T, x T) int
- func CountIf[T comparable](a []T, pred func(T) bool) int
- func DescSort[T Ordered](a []T)
- func DescStableSort[T Ordered](a []T)
- func Equal[T comparable](a, b []T) bool
- func Fill[T any](a []T, v T)
- func FillPattern[T any](a []T, pattern []T)
- func Find[T comparable](a []T, x T) (index int, ok bool)
- func FindIf[T any](a []T, cond func(T) bool) (index int, ok bool)
- func Generate[T any](a []T, gen func() T)
- func Greater[T Ordered](a, b T) bool
- func Index[T comparable](a []T, x T) int
- func IsDescSorted[T Ordered](a []T) bool
- func IsHeapFunc[T any](array []T, less LessFn[T]) bool
- func IsMinHeap[T Ordered](array []T) bool
- func IsSorted[T Ordered](a []T) bool
- func Less[T Ordered](a, b T) bool
- func LowerBound[T Ordered](a []T, value T) int
- func LowerBoundFunc[T any](a []T, value T, less LessFn[T]) int
- func MakeHeapFunc[T any](array []T, less LessFn[T])
- func MakeMinHeap[T Ordered](array []T)
- func Max[T Ordered](a, b T) T
- func MaxN[T Ordered](a ...T) T
- func Min[T Ordered](a, b T) T
- func MinMax[T Ordered](a, b T) (min, max T)
- func MinMaxN[T Ordered](a ...T) (min, max T)
- func MinN[T Ordered](a ...T) T
- func NoneOf[T any](a []T, pred func(T) bool) bool
- func OrderedCompare[T Ordered](a, b T) int
- func PopHeapFunc[T any](heap *[]T, less LessFn[T]) T
- func PopMinHeap[T Ordered](heap *[]T) T
- func PushHeapFunc[T any](heap *[]T, v T, less LessFn[T])
- func PushMinHeap[T Ordered](heap *[]T, v T)
- func Range[T Numeric](first, last T) []T
- func Remove[T comparable](a []T, x T) []T
- func RemoveCopy[T comparable](a []T, x T) []T
- func RemoveHeapFunc[T any](heap *[]T, i int, less LessFn[T]) T
- func RemoveIf[T any](a []T, cond func(T) bool) []T
- func RemoveIfCopy[T any](a []T, cond func(T) bool) []T
- func RemoveMinHeap[T Ordered](heap *[]T, i int) T
- func Replace[T comparable](a []T, old, new T)
- func ReplaceIf[T any](a []T, pred func(v T) bool, new T)
- func Reverse[T any](a []T)
- func ReverseCopy[T any](a []T) []T
- func Shuffle[T any](a []T)
- func Sort[T Ordered](a []T)
- func SortFunc[T any](a []T, less func(x, y T) bool)
- func StableSort[T Ordered](a []T)
- func StableSortFunc[T any](a []T, less func(x, y T) bool)
- func Sum[T Numeric](a []T) T
- func SumAs[R, T Numeric](a []T) R
- func Transform[T any](a []T, op func(T) T)
- func TransformCopy[R any, T any](a []T, op func(T) R) []R
- func TransformTo[R any, T any](a []T, op func(T) R, b []R) []R
- func Unique[T comparable](a []T) []T
- func UniqueCopy[T comparable](a []T) []T
- func UpperBound[T Ordered](a []T, value T) int
- func UpperBoundFunc[T any](a []T, value T, less LessFn[T]) int
- type BuiltinSet
- func SetOf[K comparable](ks ...K) BuiltinSet[K]
- func (s BuiltinSet[K]) Clear()
- func (s BuiltinSet[K]) Delete(k K)
- func (s BuiltinSet[K]) Difference(other BuiltinSet[K]) BuiltinSet[K]
- func (s BuiltinSet[K]) ForEach(cb func(k K))
- func (s BuiltinSet[K]) ForEachIf(cb func(k K) bool)
- func (s BuiltinSet[K]) Has(k K) bool
- func (s BuiltinSet[K]) Insert(k K) bool
- func (s BuiltinSet[K]) InsertN(ks ...K) int
- func (s BuiltinSet[K]) Intersection(other BuiltinSet[K]) BuiltinSet[K]
- func (s BuiltinSet[K]) IsDisjointOf(other BuiltinSet[K]) bool
- func (s BuiltinSet[K]) IsEmpty() bool
- func (s BuiltinSet[K]) IsSubsetOf(other BuiltinSet[K]) bool
- func (s BuiltinSet[K]) IsSupersetOf(other BuiltinSet[K]) bool
- func (s BuiltinSet[K]) Keys() []K
- func (s BuiltinSet[K]) Len() int
- func (s BuiltinSet[K]) Remove(k K) bool
- func (s BuiltinSet[K]) RemoveN(ks ...K) int
- func (s BuiltinSet[K]) String() string
- func (s BuiltinSet[K]) Union(other BuiltinSet[K]) BuiltinSet[K]
- func (s BuiltinSet[K]) Update(other BuiltinSet[K])
- type CompareFn
- type Container
- type DList
- func DListOf[T any](vs ...T) DList[T]
- func (l *DList[T]) Back() T
- func (l *DList[T]) Clear()
- func (l *DList[T]) ForEach(cb func(val T))
- func (l *DList[T]) ForEachIf(cb func(val T) bool)
- func (l *DList[T]) ForEachMutable(cb func(val *T))
- func (l *DList[T]) ForEachMutableIf(cb func(val *T) bool)
- func (l *DList[T]) Front() T
- func (l *DList[T]) IsEmpty() bool
- func (l *DList[T]) Iterate() MutableIterator[T]
- func (l *DList[T]) Len() int
- func (l *DList[T]) PopBack() T
- func (l *DList[T]) PopFront() T
- func (l *DList[T]) PushBack(val T)
- func (l *DList[T]) PushFront(val T)
- func (l *DList[T]) String() string
- func (l *DList[T]) TryPopBack() (T, bool)
- func (l *DList[T]) TryPopFront() (T, bool)
- type DListQueue
- func NewDListQueueT any *DListQueue[T]
- func (q *DListQueue[T]) Back() T
- func (q *DListQueue[T]) Clear()
- func (q *DListQueue[T]) Front() T
- func (q *DListQueue[T]) IsEmpty() bool
- func (q *DListQueue[T]) Len() int
- func (q *DListQueue[T]) PopBack() T
- func (q *DListQueue[T]) PopFront() T
- func (q *DListQueue[T]) PushBack(val T)
- func (q *DListQueue[T]) PushFront(val T)
- func (q *DListQueue[T]) String() string
- func (q *DListQueue[T]) TryPopBack() (T, bool)
- func (q *DListQueue[T]) TryPopFront() (T, bool)
- type Deque
- type Float
- type HashFn
- type Integer
- type Iterator
- type LessFn
- type Map
- type MapIterator
- type MutableIterator
- type MutableMapIterator
- type Numeric
- type Ordered
- type Pool
- type PriorityQueue
- func NewPriorityQueueT Ordered *PriorityQueue[T]
- func NewPriorityQueueFunc[T any](less LessFn[T]) *PriorityQueue[T]
- func NewPriorityQueueOf[T Ordered](elements ...T) *PriorityQueue[T]
- func NewPriorityQueueOn[T Ordered](slice []T) *PriorityQueue[T]
- func (pq *PriorityQueue[T]) Clear()
- func (pq *PriorityQueue[T]) IsEmpty() bool
- func (pq *PriorityQueue[T]) Len() int
- func (pq *PriorityQueue[T]) Pop() T
- func (pq *PriorityQueue[T]) Push(v T)
- func (pq *PriorityQueue[T]) Top() T
- type Queue
- type SList
- func SListOf[T any](values ...T) SList[T]
- func (l *SList[T]) Back() T
- func (l *SList[T]) Clear()
- func (l *SList[T]) ForEach(cb func(T))
- func (l *SList[T]) ForEachIf(cb func(T) bool)
- func (l *SList[T]) ForEachMutable(cb func(*T))
- func (l *SList[T]) ForEachMutableIf(cb func(*T) bool)
- func (l *SList[T]) Front() T
- func (l *SList[T]) IsEmpty() bool
- func (l *SList[T]) Iterate() MutableIterator[T]
- func (l *SList[T]) Len() int
- func (l *SList[T]) PopFront() T
- func (l *SList[T]) PushBack(v T)
- func (l *SList[T]) PushFront(v T)
- func (l *SList[T]) Reverse()
- func (l *SList[T]) Values() []T
- type Set
- type Signed
- type SkipList
- func NewSkipListK Ordered, V any *SkipList[K, V]
- func NewSkipListFromMap[K Ordered, V any](m map[K]V) *SkipList[K, V]
- func NewSkipListFunc[K any, V any](keyCmp CompareFn[K]) *SkipList[K, V]
- func (sl *SkipList[K, V]) Clear()
- func (sl *SkipList[K, V]) Find(key K) *V
- func (sl *SkipList[K, V]) FindRange(first, last K) MutableMapIterator[K, V]
- func (sl *SkipList[K, V]) ForEach(op func(K, V))
- func (sl *SkipList[K, V]) ForEachIf(op func(K, V) bool)
- func (sl *SkipList[K, V]) ForEachMutable(op func(K, *V))
- func (sl *SkipList[K, V]) ForEachMutableIf(op func(K, *V) bool)
- func (sl *SkipList[K, V]) Has(key K) bool
- func (sl *SkipList[K, V]) Insert(key K, value V)
- func (sl *SkipList[K, V]) IsEmpty() bool
- func (sl *SkipList[K, V]) Iterate() MutableMapIterator[K, V]
- func (sl *SkipList[K, V]) Len() int
- func (sl *SkipList[K, V]) LowerBound(key K) MutableMapIterator[K, V]
- func (sl *SkipList[K, V]) Remove(key K) bool
- func (sl *SkipList[K, V]) UpperBound(key K) MutableMapIterator[K, V]
- type SkipListSet
- func NewSkipListSetK Ordered *SkipListSet[K]
- func NewSkipListSetFunc[K any](cmp CompareFn[K]) *SkipListSet[K]
- func NewSkipListSetOf[K Ordered](elements ...K) *SkipListSet[K]
- func (s *SkipListSet[K]) Clear()
- func (s *SkipListSet[K]) FindRange(first, last K) Iterator[K]
- func (s *SkipListSet[K]) ForEach(f func(K))
- func (s *SkipListSet[K]) ForEachIf(f func(K) bool)
- func (s *SkipListSet[K]) Has(key K) bool
- func (s *SkipListSet[K]) Insert(key K) bool
- func (s *SkipListSet[K]) InsertN(keys ...K) int
- func (s *SkipListSet[K]) IsEmpty() bool
- func (s *SkipListSet[K]) Keys() []K
- func (s *SkipListSet[K]) Len() int
- func (s *SkipListSet[K]) LowerBound(key K) Iterator[K]
- func (s *SkipListSet[K]) Remove(key K) bool
- func (s *SkipListSet[K]) RemoveN(keys ...K) int
- func (s *SkipListSet[K]) UpperBound(key K) Iterator[K]
- type SortedMap
- type SortedSet
- type Stack
- func NewStackT any *Stack[T]
- func NewStackCap[T any](capicity int) *Stack[T]
- func (s Stack[T]) Cap() int
- func (s *Stack[T]) Clear()
- func (s Stack[T]) IsEmpty() bool
- func (s Stack[T]) Len() int
- func (s *Stack[T]) Pop() T
- func (s *Stack[T]) Push(t T)
- func (s Stack[T]) Top() T
- func (s *Stack[T]) TryPop() (val T, ok bool)
- type Unsigned
- type Vector
- func AsVector[T any](s []T) Vector[T]
- func MakeVectorT any Vector[T]
- func MakeVectorCap[T any](c int) Vector[T]
- func VectorOf[T any](v ...T) Vector[T]
- func (v *Vector[T]) Append(x ...T)
- func (v *Vector[T]) At(i int) T
- func (v Vector[T]) Back() T
- func (v *Vector[T]) Cap() int
- func (v *Vector[T]) Clear()
- func (v Vector[T]) ForEach(cb func(val T))
- func (v Vector[T]) ForEachIf(cb func(val T) bool)
- func (v Vector[T]) ForEachMutable(cb func(val *T))
- func (v Vector[T]) ForEachMutableIf(cb func(val *T) bool)
- func (v *Vector[T]) Insert(i int, x ...T)
- func (v *Vector[T]) IsEmpty() bool
- func (v Vector[T]) Iterate() MutableIterator[T]
- func (v Vector[T]) IterateRange(i, j int) MutableIterator[T]
- func (v *Vector[T]) Len() int
- func (v *Vector[T]) PopBack() T
- func (v *Vector[T]) PushBack(x T)
- func (v *Vector[T]) Remove(i int)
- func (v *Vector[T]) RemoveLength(i int, len int)
- func (v *Vector[T]) RemoveRange(i, j int)
- func (v *Vector[T]) Reserve(l int)
- func (v *Vector[T]) Set(i int, x T)
- func (v *Vector[T]) Shrink()
- func (v *Vector[T]) TryPopBack() (T, bool)
func AllOf
func AllOf[T any](a []T, pred func(T) bool) bool
AllOf return true if pred(e) returns true for all emements e in a.
Complexity: O(len(a)).
func AnyOf
func AnyOf[T any](a []T, pred func(T) bool) bool
AnyOf return true if pred(e) returns true for any emements e in a.
Complexity: O(len(a)).
func Average
func Average[T Numeric](a []T) T
Average returns the average value of a.
func AverageAs
func AverageAs[R, T Numeric](a []T) R
AverageAs returns the average value of a as type R.
func BinarySearch
func BinarySearch[T Ordered](a []T, value T) (index int, ok bool)
BinarySearch returns the (index, true) to the first element in the ascending ordered slice a such that element == value, or (-1, false) if no such element is found.
Complexity: O(log(len(a))).
func BinarySearchFunc
func BinarySearchFunc[T any](a []T, value T, less LessFn[T]) (index int, ok bool)
BinarySearchFunc returns the (index, true) to the first element in the ordered slice a such that less(element, value) and less(value, element) are both false, or (-1, false) if no such element is found.
The elements in the slice a should sorted according with compare func less.
Complexity: O(log(len(a))).
func Compare
func Compare[E Ordered](a, b []E) int
Compare compares each elements in a and b.
return 0 if they are equals, return 1 if a > b, return -1 if a < b.
Complexity: O(min(len(a), len(b))).
func Copy
func Copy[T any](a []T) []T
Copy make a copy of slice a.
Complexity: O(len(a)).
func CopyTo
func CopyTo[T any](a []T, to []T) []T
CopyTo copies all elements in slice a to slice to, return the copied slice. if slice to is large enough, no memory allocation occurs.
Complexity: O(len(a)).
func Count
func Count[T comparable](a []T, x T) int
Count returns the number of elements in the slice equals to x.
Complexity: O(len(a)).
func CountIf
func CountIf[T comparable](a []T, pred func(T) bool) int
CountIf returns the number of elements in the slice which pred returns true.
Complexity: O(len(a)).
func DescSort
func DescSort[T Ordered](a []T)
DescSort sorts data in descending order. The order of equal elements is not guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func DescStableSort
func DescStableSort[T Ordered](a []T)
DescStableSort sorts data in descending order stably. The order of equivalent elements is guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func Equal
func Equal[T comparable](a, b []T) bool
Equal returns whether two slices are equal. Return true if they are the same length and all elements are equal.
Complexity: O(min(len(a), len(b))).
func Fill
func Fill[T any](a []T, v T)
Fill fills each element in slice a with new value v.
Complexity: O(len(a)).
func FillPattern
func FillPattern[T any](a []T, pattern []T)
FillPattern fills elements in slice a with specified pattern.
Complexity: O(len(a)).
func Find
func Find[T comparable](a []T, x T) (index int, ok bool)
Find find the first value x in the given slice a linearly. return (index, true) if found, return (_, false) if not found.
Complexity: O(len(a)).
func FindIf
func FindIf[T any](a []T, cond func(T) bool) (index int, ok bool)
FindIf find the first value x satisfying function cond in the given slice a linearly. return (index, true) if found, return (_, false) if not found.
Complexity: O(len(a)).
func Generate
func Generate[T any](a []T, gen func() T)
Generate fill each element of `a`` with `gen()`.
Complexity: O(len(a)).
func Greater
func Greater[T Ordered](a, b T) bool
Greater wraps the '>' operator for ordered types.
func Index
func Index[T comparable](a []T, x T) int
Index find the value x in the given slice a linearly.
Return index if found, -1 if not found.
Complexity: O(len(a)).
func IsDescSorted
func IsDescSorted[T Ordered](a []T) bool
IsDescSorted returns whether the slice a is sorted in descending order.
Complexity: O(len(a)).
func IsHeapFunc
func IsHeapFunc[T any](array []T, less LessFn[T]) bool
IsHeapFunc checks whether the elements in slice array are a min heap (accord to less).
Complexity: O(len(array)).
func IsMinHeap
func IsMinHeap[T Ordered](array []T) bool
IsMinHeap checks whether the elements in slice array are a min heap.
Complexity: O(len(array)).
func IsSorted
func IsSorted[T Ordered](a []T) bool
IsSorted returns whether the slice a is sorted in ascending order.
Complexity: O(len(a)).
func Less
func Less[T Ordered](a, b T) bool
Less wraps the '<' operator for ordered types.
func LowerBound
func LowerBound[T Ordered](a []T, value T) int
LowerBound returns an index to the first element in the ascending ordered slice a that does not satisfy element < value (i.e. greater or equal to), or len(a) if no such element is found.
Complexity: O(log(len(a))).
func LowerBoundFunc
func LowerBoundFunc[T any](a []T, value T, less LessFn[T]) int
LowerBoundFunc returns an index to the first element in the ordered slice a that does not satisfy less(element, value)), or len(a) if no such element is found.
The elements in the slice a should sorted according with compare func less.
Complexity: O(log(len(a))).
func MakeHeapFunc
func MakeHeapFunc[T any](array []T, less LessFn[T])
MakeHeapFunc build a min-heap on slice array with compare function less.
Complexity: O(len(array))
func MakeMinHeap
func MakeMinHeap[T Ordered](array []T)
MakeMinHeap build a min-heap on slice array.
Complexity: O(len(array))
func Max
func Max[T Ordered](a, b T) T
Max return the larger value between `a` and `b`.
Complexity: O(1).
func MaxN
func MaxN[T Ordered](a ...T) T
MaxN return the maximum value in the sequence `a`.
Complexity: O(len(a)).
func Min
func Min[T Ordered](a, b T) T
Min return the smaller value between `a` and `b`.
Complexity: O(1).
func MinMax
func MinMax[T Ordered](a, b T) (min, max T)
MinMax returns both min and max between a and b.
Complexity: O(1).
func MinMaxN
func MinMaxN[T Ordered](a ...T) (min, max T)
MinMaxN returns both min and max in slice a.
Complexity: O(len(a))
func MinN
func MinN[T Ordered](a ...T) T
MinN return the minimum value in the sequence `a`.
Complexity: O(len(a)).
func NoneOf
func NoneOf[T any](a []T, pred func(T) bool) bool
NoneOf return true pred(e) returns true for none emements e in a.
Complexity: O(len(a)).
func OrderedCompare
func OrderedCompare[T Ordered](a, b T) int
OrderedCompare provide default CompareFn for ordered types.
func PopHeapFunc
func PopHeapFunc[T any](heap *[]T, less LessFn[T]) T
PopHeapFunc removes and returns the minimum (according to less) element from the heap.
Complexity: O(log n) where n = len(*heap).
func PopMinHeap
func PopMinHeap[T Ordered](heap *[]T) T
PopMinHeap removes and returns the minimum element from the heap.
Complexity: O(log n) where n = len(*heap).
func PushHeapFunc
func PushHeapFunc[T any](heap *[]T, v T, less LessFn[T])
PushHeapFunc pushes a element v into the heap.
Complexity: O(log(len(*heap))).
func PushMinHeap
func PushMinHeap[T Ordered](heap *[]T, v T)
PushMinHeap pushes a element v into the min heap.
Complexity: O(log(len(*heap))).
func Range
func Range[T Numeric](first, last T) []T
Range make a []T filled with values in the `[first, last)` sequence. NOTE: the last is not included in the result.
Complexity: O(last-first).
func Remove
func Remove[T comparable](a []T, x T) []T
Remove remove the elements which equals to x from the input slice. return the processed slice with new length.
Complexity: O(len(a)).
func RemoveCopy
func RemoveCopy[T comparable](a []T, x T) []T
RemoveCopy remove all elements which equals to x from the input slice. return a new slice with processed results. The input slice is kept unchanged.
Complexity: O(len(a)).
func RemoveHeapFunc
func RemoveHeapFunc[T any](heap *[]T, i int, less LessFn[T]) T
RemoveHeapFunc removes and returns the element at index i from the heap.
Complexity: is O(log(n)) where n = len(*heap).
func RemoveIf
func RemoveIf[T any](a []T, cond func(T) bool) []T
RemoveIf remove each element which make cond(x) returns true from the input slice, copy other elements to a new slice and return it.
Complexity: O(len(a)).
func RemoveIfCopy
func RemoveIfCopy[T any](a []T, cond func(T) bool) []T
RemoveIfCopy drops each element which make cond(x) returns true from the input slice, copy other elements to a new slice and return it. The input slice is kept unchanged.
Complexity: O(len(a)).
func RemoveMinHeap
func RemoveMinHeap[T Ordered](heap *[]T, i int) T
RemoveMinHeap removes and returns the element at index i from the min heap.
Complexity: is O(log(n)) where n = len(*heap).
func Replace
func Replace[T comparable](a []T, old, new T)
Replace replaces every element that equals to old with new.
Complexity: O(len(a)).
func ReplaceIf
func ReplaceIf[T any](a []T, pred func(v T) bool, new T)
ReplaceIf replaces every element that make preq returns true with new.
Complexity: O(len(a)).
func Reverse
func Reverse[T any](a []T)
Reverse reverses the order of the elements in the slice a.
Complexity: O(len(a)).
func ReverseCopy
func ReverseCopy[T any](a []T) []T
ReverseCopy returns a reversed copy of slice a.
Complexity: O(len(a)).
func Shuffle
func Shuffle[T any](a []T)
Shuffle pseudo-randomizes the order of elements.
Complexity: O(len(a)).
func Sort
func Sort[T Ordered](a []T)
Sort sorts data in ascending order. The order of equal elements is not guaranteed to be preserved.
Complexity: O(N*log(N)), where N=len(a).
func SortFunc
func SortFunc[T any](a []T, less func(x, y T) bool)
SortFunc sorts data in ascending order with compare func less. The order of equal elements is not guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func StableSort
func StableSort[T Ordered](a []T)
StableSort sorts data in ascending order stably. The order of equivalent elements is guaranteed to be preserved.
Complexity: O(N*log(N)^2), where N=len(a).
func StableSortFunc
func StableSortFunc[T any](a []T, less func(x, y T) bool)
StableSortFunc sorts data in ascending order with compare func less stably. The order of equivalent elements is guaranteed to be preserved.
Complexity: O(N*log(N)), N=len(a).
func Sum
func Sum[T Numeric](a []T) T
Sum summarize all elements in a. returns the result as type R, you should use SumAs if T can't hold the result. Complexity: O(len(a)).
func SumAs
func SumAs[R, T Numeric](a []T) R
SumAs summarize all elements in a. returns the result as type R, this is useful when T is too small to hold the result. Complexity: O(len(a)).
func Transform
func Transform[T any](a []T, op func(T) T)
Transform applies the function op to each element in slice a and set it back to the same place in a.
Complexity: O(len(a)).
func TransformCopy
func TransformCopy[R any, T any](a []T, op func(T) R) []R
TransformCopy applies the function op to each element in slice a and return all the result as a slice.
Complexity: O(len(a)).
func TransformTo
func TransformTo[R any, T any](a []T, op func(T) R, b []R) []R
TransformTo applies the function op to each element in slice a and fill it to slice b, return the transformed slice. If cap(b) >= len(a), no memory allocation.
Complexity: O(len(a)).
func Unique
func Unique[T comparable](a []T) []T
Unique remove adjacent repeated elements from the input slice. return the processed slice with new length.
Complexity: O(len(a)).
func UniqueCopy
func UniqueCopy[T comparable](a []T) []T
UniqueCopy remove adjacent repeated elements from the input slice. return the result slice, and the input slice is kept unchanged.
Complexity: O(len(a)).
func UpperBound
func UpperBound[T Ordered](a []T, value T) int
UpperBound returns an index to the first element in the ascending ordered slice a such that value < element (i.e. strictly greater), or len(a) if no such element is found.
Complexity: O(log(len(a))).
func UpperBoundFunc
func UpperBoundFunc[T any](a []T, value T, less LessFn[T]) int
UpperBoundFunc returns an index to the first element in the ordered slice a such that less(value, element)) is true (i.e. strictly greater), or len(a) if no such element is found.
The elements in the slice a should sorted according with compare func less.
Complexity: O(log(len(a))).
type BuiltinSet
BuiltinSet is an associative container that contains an unordered set of unique objects of type K.
type BuiltinSet[K comparable] map[K]struct{}
func SetOf
func SetOf[K comparable](ks ...K) BuiltinSet[K]
SetOf creates a new BuiltinSet object with the initial content from ks.
func (BuiltinSet[K]) Clear
func (s BuiltinSet[K]) Clear()
Clear implements the Container interface.
func (BuiltinSet[K]) Delete
func (s BuiltinSet[K]) Delete(k K)
Delete deletes an element from the set. It returns nothing, so it's faster than Remove.
func (BuiltinSet[K]) Difference
func (s BuiltinSet[K]) Difference(other BuiltinSet[K]) BuiltinSet[K]
Difference returns a new set with elements in the set that are not in other.
func (BuiltinSet[K]) ForEach
func (s BuiltinSet[K]) ForEach(cb func(k K))
ForEach implements the Set interface.
func (BuiltinSet[K]) ForEachIf
func (s BuiltinSet[K]) ForEachIf(cb func(k K) bool)
ForEachIf implements the Container interface.
func (BuiltinSet[K]) Has
func (s BuiltinSet[K]) Has(k K) bool
Has implements the Set interface.
func (BuiltinSet[K]) Insert
func (s BuiltinSet[K]) Insert(k K) bool
Insert implements the Set interface.
func (BuiltinSet[K]) InsertN
func (s BuiltinSet[K]) InsertN(ks ...K) int
InsertN implements the Set interface.
func (BuiltinSet[K]) Intersection
func (s BuiltinSet[K]) Intersection(other BuiltinSet[K]) BuiltinSet[K]
Intersection returns a new set with elements common to the set and other.
func (BuiltinSet[K]) IsDisjointOf
func (s BuiltinSet[K]) IsDisjointOf(other BuiltinSet[K]) bool
IsDisjointOf return True if the set has no elements in common with other. Sets are disjoint if and only if their intersection is the empty set.
func (BuiltinSet[K]) IsEmpty
func (s BuiltinSet[K]) IsEmpty() bool
IsEmpty implements the Container interface.
func (BuiltinSet[K]) IsSubsetOf
func (s BuiltinSet[K]) IsSubsetOf(other BuiltinSet[K]) bool
IsSubsetOf tests whether every element in the set is in other.
func (BuiltinSet[K]) IsSupersetOf
func (s BuiltinSet[K]) IsSupersetOf(other BuiltinSet[K]) bool
IsSupersetOf tests whether every element in other is in the set.
func (BuiltinSet[K]) Keys
func (s BuiltinSet[K]) Keys() []K
Keys return a copy of all keys as a slice.
func (BuiltinSet[K]) Len
func (s BuiltinSet[K]) Len() int
Len implements the Container interface.
func (BuiltinSet[K]) Remove
func (s BuiltinSet[K]) Remove(k K) bool
Remove implements the Set interface.
func (BuiltinSet[K]) RemoveN
func (s BuiltinSet[K]) RemoveN(ks ...K) int
RemoveN implements the Set interface.
func (BuiltinSet[K]) String
func (s BuiltinSet[K]) String() string
String implements the fmt.Stringer interface.
func (BuiltinSet[K]) Union
func (s BuiltinSet[K]) Union(other BuiltinSet[K]) BuiltinSet[K]
Union returns a new set with elements from the set and other.
func (BuiltinSet[K]) Update
func (s BuiltinSet[K]) Update(other BuiltinSet[K])
Update adds all elements from other to set. set |= other.
type CompareFn
CompareFn is a 3 way compare function that returns 1 if a > b, returns 0 if a == b, returns -1 if a < b.
type CompareFn[T any] func(a, b T) int
type Container
Container is a holder object that stores a collection of other objects.
type Container interface {
IsEmpty() bool // IsEmpty checks if the container has no elements.
Len() int // Len returns the number of elements in the container.
Clear() // Clear erases all elements from the container. After this call, Len() returns zero.
}
type DList
DList is a doubly linked list.
type DList[T any] struct {
// contains filtered or unexported fields
}
func DListOf
func DListOf[T any](vs ...T) DList[T]
DListOf make a new DList from a serial of values.
func (*DList[T]) Back
func (l *DList[T]) Back() T
Back returns the last element in the container.
func (*DList[T]) Clear
func (l *DList[T]) Clear()
Clear cleanup the list.
func (*DList[T]) ForEach
func (l *DList[T]) ForEach(cb func(val T))
ForEach iterate the list, apply each element to the cb callback function.
func (*DList[T]) ForEachIf
func (l *DList[T]) ForEachIf(cb func(val T) bool)
ForEachIf iterate the list, apply each element to the cb callback function, stop if cb returns false.
func (*DList[T]) ForEachMutable
func (l *DList[T]) ForEachMutable(cb func(val *T))
ForEachMutable iterate the list, apply pointer of each element to the cb callback function.
func (*DList[T]) ForEachMutableIf
func (l *DList[T]) ForEachMutableIf(cb func(val *T) bool)
ForEachMutableIf iterate the list, apply pointer of each element to the cb callback function, stop if cb returns false.
func (*DList[T]) Front
func (l *DList[T]) Front() T
Front returns the first element in the container.
func (*DList[T]) IsEmpty
func (l *DList[T]) IsEmpty() bool
IsEmpty return whether the list is empty.
func (*DList[T]) Iterate
func (l *DList[T]) Iterate() MutableIterator[T]
Iterate returns an iterator to the first element in the list.
func (*DList[T]) Len
func (l *DList[T]) Len() int
Len return the length of the list.
func (*DList[T]) PopBack
func (l *DList[T]) PopBack() T
PopBack popups a element from the back of the list.
func (*DList[T]) PopFront
func (l *DList[T]) PopFront() T
PopFront popups a element from the front of the list.
func (*DList[T]) PushBack
func (l *DList[T]) PushBack(val T)
PushBack pushes an element at the back of the list.
func (*DList[T]) PushFront
func (l *DList[T]) PushFront(val T)
PushFront pushes an element at the front of the list.
func (*DList[T]) String
func (l *DList[T]) String() string
String convert the list to string.
func (*DList[T]) TryPopBack
func (l *DList[T]) TryPopBack() (T, bool)
TryPopBack tries to popup a element from the back of the list.
func (*DList[T]) TryPopFront
func (l *DList[T]) TryPopFront() (T, bool)
TryPopFront tries to popup a element from the front of the list.
type DListQueue
DListQueue is a FIFO container
type DListQueue[T any] struct {
// contains filtered or unexported fields
}
func NewDListQueue
func NewDListQueue[T any]() *DListQueue[T]
NewDListQueue create a new Queue object.
func (*DListQueue[T]) Back
func (q *DListQueue[T]) Back() T
Back returns the last element in the container.
func (*DListQueue[T]) Clear
func (q *DListQueue[T]) Clear()
Clear implements the Container interface.
func (*DListQueue[T]) Front
func (q *DListQueue[T]) Front() T
Front returns the first element in the container.
func (*DListQueue[T]) IsEmpty
func (q *DListQueue[T]) IsEmpty() bool
IsEmpty implements the Container interface.
func (*DListQueue[T]) Len
func (q *DListQueue[T]) Len() int
Len implements the Container interface.
func (*DListQueue[T]) PopBack
func (q *DListQueue[T]) PopBack() T
PopBack popups an element from the back of the queue.
func (*DListQueue[T]) PopFront
func (q *DListQueue[T]) PopFront() T
PopFront popups an element from the front of the queue.
func (*DListQueue[T]) PushBack
func (q *DListQueue[T]) PushBack(val T)
PushBack pushed an element to the back of the queue.
func (*DListQueue[T]) PushFront
func (q *DListQueue[T]) PushFront(val T)
PushFront pushed an element to the front of the queue.
func (*DListQueue[T]) String
func (q *DListQueue[T]) String() string
Len implements the fmt.Stringer interface.
func (*DListQueue[T]) TryPopBack
func (q *DListQueue[T]) TryPopBack() (T, bool)
TryPopBack tries popuping an element from the back of the queue.
func (*DListQueue[T]) TryPopFront
func (q *DListQueue[T]) TryPopFront() (T, bool)
TryPopFront tries popuping an element from the front of the queue.
type Deque
Deque is a container that can add and remove elements from both ends.
type Deque[T any] interface {
Container
Front() T // Front returns the first element in the container.
Back() T // Back returns the last element in the container.
PushFront(T) // PushBack pushes an element at the front of the container.
PushBack(T) // PushBack pushes an element at the back of the container.
PopFront() T // PopBack popups a front from the back of the container.
PopBack() T // PopBack popups a element from the back of the container.
TryPopFront() (T, bool) // TryPopFront tries to popup a element from the front of the container.
TryPopBack() (T, bool) // TryPopBack tries to popup a element from the back of the container.
}
type Float
Float is a constraint that permits any floating-point type. If future releases of Go add new predeclared floating-point types, this constraint will be modified to include them.
type Float interface {
// contains filtered or unexported methods
}
type HashFn
HashFn is a function that returns the hash of 't'.
type HashFn[T any] func(t T) uint64
type Integer
Integer is a constraint that permits any integer type. If future releases of Go add new predeclared integer types, this constraint will be modified to include them.
type Integer interface {
// contains filtered or unexported methods
}
type Iterator
Iterator is the interface for container's iterator.
type Iterator[T any] interface {
IsNotEnd() bool // Whether it is point to the end of the range.
MoveToNext() // Let it point to the next element.
Value() T // Return the value of current element.
}
type LessFn
LessFn is a function that returns whether 'a' is less than 'b'.
type LessFn[T any] func(a, b T) bool
type Map
Map is a associative container that contains key-value pairs with unique keys.
type Map[K any, V any] interface {
Container
Has(K) bool // Checks whether the container contains element with specific key.
Find(K) *V // Finds element with specific key.
Insert(K, V) // Inserts a key-value pair in to the container or replace existing value.
Remove(K) bool // Remove element with specific key.
ForEach(func(K, V)) // Iterate the container.
ForEachIf(func(K, V) bool) // Iterate the container, stops when the callback returns false.
ForEachMutable(func(K, *V)) // Iterate the container, *V is mutable.
ForEachMutableIf(func(K, *V) bool) // Iterate the container, *V is mutable, stops when the callback returns false.
}
type MapIterator
MapIterator is the interface for map's iterator.
type MapIterator[K any, V any] interface {
Key() K // The key of the element
// contains filtered or unexported methods
}
type MutableIterator
MutableIterator is the interface for container's mutable iterator.
type MutableIterator[T any] interface {
Pointer() *T // Return the pointer to the value of current element.
// contains filtered or unexported methods
}
type MutableMapIterator
MutableMapIterator is the interface for map's mutable iterator.
type MutableMapIterator[K any, V any] interface {
Key() K // The key of the element
// contains filtered or unexported methods
}
type Numeric
Numeric is a constraint that permits any numeric type.
type Numeric interface {
// contains filtered or unexported methods
}
type Ordered
Ordered is a constraint that permits any ordered type: any type that supports the operators < <= >= >. If future releases of Go add new ordered types, this constraint will be modified to include them.
type Ordered interface {
// contains filtered or unexported methods
}
type Pool
Pool is a type safed sync.Pool.
type Pool[T any] sync.Pool
func MakePool
func MakePool[T any]() Pool[T]
MakePool returns a Pool object
func MakePoolWithNew
func MakePoolWithNew[T any](new func() *T) Pool[T]
MakePoolWithNew returns a Pool object with specified new function.
func (*Pool[T]) Get
func (pool *Pool[T]) Get() *T
Get selects an arbitrary item from the Pool, removes it from the Pool, and returns it to the caller.
func (*Pool[T]) Put
func (pool *Pool[T]) Put(x *T)
Put puts x to the pool.
type PriorityQueue
PriorityQueue is an queue with priority. The elements of the priority queue are ordered according to their natural ordering, or by a less function provided at construction time, depending on which constructor is used.
type PriorityQueue[T any] struct {
// contains filtered or unexported fields
}
Example
This example inserts several ints into an IntHeap, checks the minimum, and removes them in order of priority.
{
h := NewPriorityQueue[int]()
h.Push(3)
h.Push(2)
h.Push(1)
h.Push(5)
fmt.Printf("minimum: %d\n", h.Top())
for h.Len() > 0 {
fmt.Printf("%d ", h.Pop())
}
}
minimum: 1
1 2 3 5
func NewPriorityQueue
func NewPriorityQueue[T Ordered]() *PriorityQueue[T]
NewPriorityQueue creates an empty priority object.
func NewPriorityQueueFunc
func NewPriorityQueueFunc[T any](less LessFn[T]) *PriorityQueue[T]
NewPriorityQueueFunc creates an empty priority object with specified compare function less.
func NewPriorityQueueOf
func NewPriorityQueueOf[T Ordered](elements ...T) *PriorityQueue[T]
NewPriorityQueueOf creates a new priority object with specified initial elements.
func NewPriorityQueueOn
func NewPriorityQueueOn[T Ordered](slice []T) *PriorityQueue[T]
NewPriorityQueueOn creates a new priority object on the specified slices. The slice become a heap after the call.
func (*PriorityQueue[T]) Clear
func (pq *PriorityQueue[T]) Clear()
Clear clear the priority queue.
func (*PriorityQueue[T]) IsEmpty
func (pq *PriorityQueue[T]) IsEmpty() bool
IsEmpty checks whether priority queue has no elements.
func (*PriorityQueue[T]) Len
func (pq *PriorityQueue[T]) Len() int
Len returns the number of elements in the priority queue.
func (*PriorityQueue[T]) Pop
func (pq *PriorityQueue[T]) Pop() T
Pop removes the top element in the priority queue.
func (*PriorityQueue[T]) Push
func (pq *PriorityQueue[T]) Push(v T)
Push pushes the given element v to the priority queue.
func (*PriorityQueue[T]) Top
func (pq *PriorityQueue[T]) Top() T
Top returns the top element in the priority queue.
type Queue
Queue is a container that can add elements to one end and remove elements from the other end.
type Queue[T any] interface {
Container
Front() // Front returns the first element in the container.
Back() // Back returns the last element in the container.
Push(T) // Push pushes an element at the back of the container.
Pop() T // Pop popups a front from the back of the container.
TryPop() (T, bool) // TryPop tries to popup a element from the front of the container.
}
type SList
SList is a singly linked list.
type SList[T any] struct {
// contains filtered or unexported fields
}
func SListOf
func SListOf[T any](values ...T) SList[T]
SListOf return a SList that contains values.
func (*SList[T]) Back
func (l *SList[T]) Back() T
Back returns the last element in the list.
func (*SList[T]) Clear
func (l *SList[T]) Clear()
Clear erases all elements from the container. After this call, Len() returns zero.
func (*SList[T]) ForEach
func (l *SList[T]) ForEach(cb func(T))
ForEach iterate the list, apply each element to the cb callback function.
func (*SList[T]) ForEachIf
func (l *SList[T]) ForEachIf(cb func(T) bool)
ForEachIf iterate the container, apply each element to the cb callback function, stop if cb returns false.
func (*SList[T]) ForEachMutable
func (l *SList[T]) ForEachMutable(cb func(*T))
ForEachMutable iterate the container, apply pointer of each element to the cb callback function.
func (*SList[T]) ForEachMutableIf
func (l *SList[T]) ForEachMutableIf(cb func(*T) bool)
ForEachMutableIf iterate the container, apply pointer of each element to the cb callback function, stop if cb returns false.
func (*SList[T]) Front
func (l *SList[T]) Front() T
Front returns the first element in the list.
func (*SList[T]) IsEmpty
func (l *SList[T]) IsEmpty() bool
IsEmpty checks if the container has no elements.
func (*SList[T]) Iterate
func (l *SList[T]) Iterate() MutableIterator[T]
Iterate returns an iterator to the whole container.
func (*SList[T]) Len
func (l *SList[T]) Len() int
Len returns the number of elements in the container.
func (*SList[T]) PopFront
func (l *SList[T]) PopFront() T
PopFront popups an element from the front of the list. The list must be non-empty!
func (*SList[T]) PushBack
func (l *SList[T]) PushBack(v T)
PushBack pushed an element to the tail of the list.
func (*SList[T]) PushFront
func (l *SList[T]) PushFront(v T)
PushFront pushed an element to the front of the list.
func (*SList[T]) Reverse
func (l *SList[T]) Reverse()
Reverse reverses the order of all elements in the container.
func (*SList[T]) Values
func (l *SList[T]) Values() []T
Values copies all elements in the container to a slice and return it.
type Set
Set is a containers that store unique elements.
type Set[K any] interface {
Container
Has(K) bool // Checks whether the container contains element with specific key.
Insert(K) bool // Inserts a element in to the container or replace existing value.
InsertN(...K) int // Inserts multiple elements in to the container or replace existing value.
Remove(K) bool // Remove specific element, return true if element was in the container.
RemoveN(...K) int // Remove multiple elements, return the number of removed elements.
ForEach(func(K)) // Iterate the container.
ForEachIf(func(K) bool) // Iterate the container, stops when the callback returns false.
}
type Signed
Signed is a constraint that permits any signed integer type. If future releases of Go add new predeclared signed integer types, this constraint will be modified to include them.
type Signed interface {
// contains filtered or unexported methods
}
type SkipList
SkipList is a probabilistic data structure that seem likely to supplant balanced trees as the implementation method of choice for many applications. Skip list algorithms have the same asymptotic expected time bounds as balanced trees and are simpler, faster and use less space.
See https://en.wikipedia.org/wiki/Skip_list for more details.
type SkipList[K any, V any] struct {
// contains filtered or unexported fields
}
func NewSkipList
func NewSkipList[K Ordered, V any]() *SkipList[K, V]
NewSkipList creates a new SkipList for Ordered key type.
func NewSkipListFromMap
func NewSkipListFromMap[K Ordered, V any](m map[K]V) *SkipList[K, V]
NewSkipListFromMap creates a new SkipList from a map.
func NewSkipListFunc
func NewSkipListFunc[K any, V any](keyCmp CompareFn[K]) *SkipList[K, V]
NewSkipListFunc creates a new SkipList with specified compare function keyCmp.
func (*SkipList[K, V]) Clear
func (sl *SkipList[K, V]) Clear()
Clear implements the Container interface.
func (*SkipList[K, V]) Find
func (sl *SkipList[K, V]) Find(key K) *V
Find returns the value associated with the passed key if the key is in the skiplist, otherwise returns nil.
func (*SkipList[K, V]) FindRange
func (sl *SkipList[K, V]) FindRange(first, last K) MutableMapIterator[K, V]
FindRange returns an iterator in range [first, last) (last is not included).
func (*SkipList[K, V]) ForEach
func (sl *SkipList[K, V]) ForEach(op func(K, V))
ForEach implements the Map interface.
func (*SkipList[K, V]) ForEachIf
func (sl *SkipList[K, V]) ForEachIf(op func(K, V) bool)
ForEachIf implements the Map interface.
func (*SkipList[K, V]) ForEachMutable
func (sl *SkipList[K, V]) ForEachMutable(op func(K, *V))
ForEachMutable implements the Map interface.
func (*SkipList[K, V]) ForEachMutableIf
func (sl *SkipList[K, V]) ForEachMutableIf(op func(K, *V) bool)
ForEachMutableIf implements the Map interface.
func (*SkipList[K, V]) Has
func (sl *SkipList[K, V]) Has(key K) bool
Has implement the Map interface.
func (*SkipList[K, V]) Insert
func (sl *SkipList[K, V]) Insert(key K, value V)
Insert inserts a key-value pair into the skiplist. If the key is already in the skip list, it's value will be updated.
func (*SkipList[K, V]) IsEmpty
func (sl *SkipList[K, V]) IsEmpty() bool
IsEmpty implements the Container interface.
func (*SkipList[K, V]) Iterate
func (sl *SkipList[K, V]) Iterate() MutableMapIterator[K, V]
Iterate return an iterator to the skiplist.
func (*SkipList[K, V]) Len
func (sl *SkipList[K, V]) Len() int
Len implements the Container interface.
func (*SkipList[K, V]) LowerBound
func (sl *SkipList[K, V]) LowerBound(key K) MutableMapIterator[K, V]
LowerBound returns an iterator to the first element in the skiplist that does not satisfy element < value (i.e. greater or equal to), or a end iterator if no such element is found.
func (*SkipList[K, V]) Remove
func (sl *SkipList[K, V]) Remove(key K) bool
Remove removes the key-value pair associated with the passed key and returns true if the key is in the skiplist, otherwise returns false.
func (*SkipList[K, V]) UpperBound
func (sl *SkipList[K, V]) UpperBound(key K) MutableMapIterator[K, V]
UpperBound returns an iterator to the first element in the skiplist that does not satisfy value < element (i.e. strictly greater), or a end iterator if no such element is found.
type SkipListSet
SkipListSet is a SortedSet implemented with skiplist.
type SkipListSet[K any] SkipList[K, struct{}]
func NewSkipListSet
func NewSkipListSet[K Ordered]() *SkipListSet[K]
NewSkipListSet creates a new SkipListSet object.
func NewSkipListSetFunc
func NewSkipListSetFunc[K any](cmp CompareFn[K]) *SkipListSet[K]
NewSkipListSetFunc creates a new SkipListSet object with specified compare function.
func NewSkipListSetOf
func NewSkipListSetOf[K Ordered](elements ...K) *SkipListSet[K]
NewSkipListSetOf creates a new SkipListSet object with specified elements.
func (*SkipListSet[K]) Clear
func (s *SkipListSet[K]) Clear()
Clear implements the SortedSet interface.
func (*SkipListSet[K]) FindRange
func (s *SkipListSet[K]) FindRange(first, last K) Iterator[K]
FindRange implements the SortedSet interface.
func (*SkipListSet[K]) ForEach
func (s *SkipListSet[K]) ForEach(f func(K))
ForEach implements the SortedSet interface.
func (*SkipListSet[K]) ForEachIf
func (s *SkipListSet[K]) ForEachIf(f func(K) bool)
ForEachIf implements the SortedSet interface.
func (*SkipListSet[K]) Has
func (s *SkipListSet[K]) Has(key K) bool
Has implements the SortedSet interface.
func (*SkipListSet[K]) Insert
func (s *SkipListSet[K]) Insert(key K) bool
Insert implements the SortedSet interface.
func (*SkipListSet[K]) InsertN
func (s *SkipListSet[K]) InsertN(keys ...K) int
InsertN implements the SortedSet interface.
func (*SkipListSet[K]) IsEmpty
func (s *SkipListSet[K]) IsEmpty() bool
IsEmpty implements the SortedSet interface.
func (*SkipListSet[K]) Keys
func (s *SkipListSet[K]) Keys() []K
Keys return a copy of sorted keys as slice.
func (*SkipListSet[K]) Len
func (s *SkipListSet[K]) Len() int
Len implements the SortedSet interface.
func (*SkipListSet[K]) LowerBound
func (s *SkipListSet[K]) LowerBound(key K) Iterator[K]
LowerBound implements the SortedSet interface.
func (*SkipListSet[K]) Remove
func (s *SkipListSet[K]) Remove(key K) bool
Remove implements the SortedSet interface.
func (*SkipListSet[K]) RemoveN
func (s *SkipListSet[K]) RemoveN(keys ...K) int
RemoveN implements the SortedSet interface.
func (*SkipListSet[K]) UpperBound
func (s *SkipListSet[K]) UpperBound(key K) Iterator[K]
UpperBound implements the SortedSet interface.
type SortedMap
SortedMap is a Map that provides a total ordering on its keys.
type SortedMap[K any, V any] interface {
// LowerBound returns an iterator to the first element in the container that
// does not satisfy element.key < value (i.e. greater or equal to),
// or a end iterator if no such element is found.
LowerBound(K) MutableMapIterator[K, V]
// UpperBound returns an iterator to the first element in the container that
// does not satisfy value < element.key (i.e. strictly greater),
// or a end iterator if no such element is found.
UpperBound(K) MutableMapIterator[K, V]
// FindRange returns an iterator in range [first, last) (last is not included).
FindRange(K, K) MutableMapIterator[K, V]
// contains filtered or unexported methods
}
type SortedSet
SortedSet is a Set that provides a total ordering on its elements.
type SortedSet[K any] interface {
// LowerBound returns an iterator to the first element in the container that
// does not satisfy element < value (i.e. greater or equal to),
// or a end iterator if no such element is found.
LowerBound(K) Iterator[K]
// UpperBound returns an iterator to the first element in the container that
// does not satisfy value < element (i.e. strictly greater),
// or a end iterator if no such element is found.
UpperBound(K) Iterator[K]
// FindRange returns an iterator in range [first, last) (last is not included).
FindRange(K, K) Iterator[K]
// contains filtered or unexported methods
}
type Stack
Stack s is a container adaptor that provides the functionality of a stack, a LIFO (last-in, first-out) data structure.
type Stack[T any] struct {
// contains filtered or unexported fields
}
func NewStack
func NewStack[T any]() *Stack[T]
NewStack creates a new Stack object.
func NewStackCap
func NewStackCap[T any](capicity int) *Stack[T]
NewStackCap creates a new Stack object with the specified capicity.
func (Stack[T]) Cap
func (s Stack[T]) Cap() int
Cap returns the capacity of the stack.
func (*Stack[T]) Clear
func (s *Stack[T]) Clear()
Clear implements the Container interface.
func (Stack[T]) IsEmpty
func (s Stack[T]) IsEmpty() bool
IsEmpty implements the Container interface.
func (Stack[T]) Len
func (s Stack[T]) Len() int
Len implements the Container interface.
func (*Stack[T]) Pop
func (s *Stack[T]) Pop() T
Pop popups an element from the top of the stack. It must be called when IsEmpty() returned false, otherwise it will panic.
func (*Stack[T]) Push
func (s *Stack[T]) Push(t T)
Push pushes the element to the top of the stack.
func (Stack[T]) Top
func (s Stack[T]) Top() T
Top returns the top element in the stack. It must be called when s.IsEmpty() returned false, otherwise it will panic.
func (*Stack[T]) TryPop
func (s *Stack[T]) TryPop() (val T, ok bool)
TryPop tries to popup an element from the top of the stack.
type Unsigned
Unsigned is a constraint that permits any unsigned integer type. If future releases of Go add new predeclared unsigned integer types, this constraint will be modified to include them.
type Unsigned interface {
// contains filtered or unexported methods
}
type Vector
Vector is a sequence container representing array that can change in size.
type Vector[T any] []T
func AsVector
func AsVector[T any](s []T) Vector[T]
AsVector casts a slice as a Vector object.
func MakeVector
func MakeVector[T any]() Vector[T]
MakeVector creates an empty Vector object.
func MakeVectorCap
func MakeVectorCap[T any](c int) Vector[T]
MakeVectorCap creates an empty Vector object with specified capacity.
func VectorOf
func VectorOf[T any](v ...T) Vector[T]
VectorOf creates a Vector object with initial values.
func (*Vector[T]) Append
func (v *Vector[T]) Append(x ...T)
Append appends the values x... to the tail of the vector.
func (*Vector[T]) At
func (v *Vector[T]) At(i int) T
At returns the element value at the index i. You can also use the [] operator, and it's better.
func (Vector[T]) Back
func (v Vector[T]) Back() T
Back returns the element at the end of the vector. It must be called when IsEmpty() returned false, otherwise it will panic.
func (*Vector[T]) Cap
func (v *Vector[T]) Cap() int
Cap returns the capacity of the vector.
func (*Vector[T]) Clear
func (v *Vector[T]) Clear()
Clear erases all elements from the vector. After this call, Len() returns zero. Leaves the Cap() of the vector unchanged.
func (Vector[T]) ForEach
func (v Vector[T]) ForEach(cb func(val T))
ForEach iterate the container, apply each element to the cb callback function.
func (Vector[T]) ForEachIf
func (v Vector[T]) ForEachIf(cb func(val T) bool)
ForEachIf iterate the container, apply each element to the cb callback function, stop if cb returns false.
func (Vector[T]) ForEachMutable
func (v Vector[T]) ForEachMutable(cb func(val *T))
ForEachMutable iterate the container, apply pointer of each element to the cb callback function.
func (Vector[T]) ForEachMutableIf
func (v Vector[T]) ForEachMutableIf(cb func(val *T) bool)
ForEachMutableIf iterate the container, apply pointer of each element to the cb callback function, stop if cb returns false.
func (*Vector[T]) Insert
func (v *Vector[T]) Insert(i int, x ...T)
Insert inserts the values x... into the vector at index i. After the insertion, (*v)[i] == x[0]. Insert panics if i is out of range.
Complexity: O(len(s) + len(v)).
func (*Vector[T]) IsEmpty
func (v *Vector[T]) IsEmpty() bool
IsEmpty implements the Container interface.
func (Vector[T]) Iterate
func (v Vector[T]) Iterate() MutableIterator[T]
Iterate returns an iterator to the whole container.
func (Vector[T]) IterateRange
func (v Vector[T]) IterateRange(i, j int) MutableIterator[T]
IterateRange returns an iterator to the range [i, j) of the container.
func (*Vector[T]) Len
func (v *Vector[T]) Len() int
Len implements the Container interface.
func (*Vector[T]) PopBack
func (v *Vector[T]) PopBack() T
PopBack popups an element from the end of the vector. It must be called when IsEmpty() returned false, otherwise it will panic.
func (*Vector[T]) PushBack
func (v *Vector[T]) PushBack(x T)
PushBack pushs an element to the end of the vector.
Complexity: O(1) if v.Len() < v.Cap(), therwise O(len(v)).
func (*Vector[T]) Remove
func (v *Vector[T]) Remove(i int)
Remove removes 1 element in the vector.
Complexity: O(len(s) - i).
func (*Vector[T]) RemoveLength
func (v *Vector[T]) RemoveLength(i int, len int)
RemoveLength removes the elements in the range[i, i+len) from the vector.
func (*Vector[T]) RemoveRange
func (v *Vector[T]) RemoveRange(i, j int)
RemoveRange removes the elements in the range[i, j) from the vector.
func (*Vector[T]) Reserve
func (v *Vector[T]) Reserve(l int)
Reserve increases the capacity of the vector (the total number of elements that the vector can hold without requiring reallocation)to a value that's greater or equal to l. If l is greater than the current Cap(), new storage is allocated, otherwise the function does nothing.
Reserve() does not change the size of the vector.
func (*Vector[T]) Set
func (v *Vector[T]) Set(i int, x T)
Set sets the value of the element at the index i. You can also use the [] operator, and it's better.
func (*Vector[T]) Shrink
func (v *Vector[T]) Shrink()
Shrink removes unused capacity from the vector.
func (*Vector[T]) TryPopBack
func (v *Vector[T]) TryPopBack() (T, bool)
TryPopBack popups an element from the end of the vector.
Generated by gomarkdoc