Documentation ¶
Index ¶
- Variables
- func MapUpdate[K comparable, V any](curr map[K]V, incom map[K]V)
- func SliceContains[T comparable](data []T, value T) bool
- func SliceFilter[T any](data []T, filterFn func(v T, i int) bool) []T
- func SliceFindIndex[T any](data []T, cmp func(v T) bool) int
- func SliceMap[T any, U any](data []T, mapFn func(v T, i int) U) []U
- func SliceReduce[T any, U any](data []T, reduceFn func(acc U, curr T, i int) U, initial U) U
- type BinTree
- type CircularList
- func (clist *CircularList[T]) Append(v T)
- func (clist *CircularList[T]) ForEach(fn func(i int, item T) bool)
- func (clist *CircularList[T]) Get(idx int) T
- func (clist *CircularList[T]) Head() T
- func (clist *CircularList[T]) Last() T
- func (clist *CircularList[T]) Len() int
- func (clist *CircularList[T]) Prepend(v T)
- func (clist *CircularList[T]) ShiftUntil(fn func(item T) bool)
- type Comparable
- type ConcurrentMap
- func (cm *ConcurrentMap[K, T]) AsMap() map[K]T
- func (cm *ConcurrentMap[K, T]) Delete(k K)
- func (cm *ConcurrentMap[K, T]) Filter(fn func(k K, v T) bool) *ConcurrentMap[K, T]
- func (cm *ConcurrentMap[K, T]) ForEach(fn func(k K, v T))
- func (cm *ConcurrentMap[K, T]) Get(k K) T
- func (cm *ConcurrentMap[K, T]) GetWithTest(k K) (T, bool)
- func (cm *ConcurrentMap[K, T]) HasKey(k K) bool
- func (cm *ConcurrentMap[K, T]) Keys() []K
- func (cm *ConcurrentMap[K, T]) Len() int
- func (cm *ConcurrentMap[K, T]) MarshalJSON() ([]byte, error)
- func (cm *ConcurrentMap[K, T]) Set(k K, v T)
- func (cm *ConcurrentMap[K, T]) Update(fn func(k K, v T) T)
- func (cm *ConcurrentMap[K, T]) Values() []T
- type Multidict
- type Set
- func (set *Set[T]) Add(value T)
- func (set *Set[T]) Contains(value T) bool
- func (set *Set[T]) ForEach(fn func(item T))
- func (set *Set[T]) Intersect(other *Set[T]) *Set[T]
- func (set *Set[T]) Remove(value T)
- func (set *Set[T]) Size() int
- func (set *Set[T]) Sub(other *Set[T]) *Set[T]
- func (set *Set[T]) ToOrderedSlice() []T
- func (set *Set[T]) ToSlice() []T
- func (set *Set[T]) Union(other Set[T]) *Set[T]
Constants ¶
This section is empty.
Variables ¶
var ErrorStopIteration = errors.New("stopped iteration")
Functions ¶
func MapUpdate ¶ added in v0.4.6
func MapUpdate[K comparable, V any](curr map[K]V, incom map[K]V)
func SliceContains ¶
func SliceContains[T comparable](data []T, value T) bool
func SliceFilter ¶ added in v0.4.3
func SliceFindIndex ¶ added in v0.2.2
func SliceReduce ¶ added in v0.2.2
Types ¶
type BinTree ¶ added in v0.5.0
type BinTree[T Comparable] struct { // contains filtered or unexported fields }
BinTree is a simple unbalanced binary tree implementation for storing sorted values
type CircularList ¶ added in v0.3.3
type CircularList[T any] struct { // contains filtered or unexported fields }
CircularList is a structure allowing infinite appending of new items while rewriting the oldest (in terms of order of respective Append() operations) records if needed. It also allows removing oldest records based on a condition - here we expect that the values contain some value representing their order in which they have been added - typically it is a time information.
func NewCircularList ¶ added in v0.3.3
func NewCircularList[T any](capacity int) *CircularList[T]
NewCircularList is a recommended factory function for CircularList. The parameter `capacity` defines max. number of items the instance will be able to store.
func (*CircularList[T]) Append ¶ added in v0.3.3
func (clist *CircularList[T]) Append(v T)
Append adds a new item to the end of the list. In case the free capacity is depleted, then the oldest item is replaced by this new one.
func (*CircularList[T]) ForEach ¶ added in v0.3.3
func (clist *CircularList[T]) ForEach(fn func(i int, item T) bool)
ForEach runs a function fn for all the items starting from the oldest one. The iteration continues until fn returns true.
func (*CircularList[T]) Get ¶ added in v0.3.3
func (clist *CircularList[T]) Get(idx int) T
Get returns an item with a specific index. Please note that for CircularList, this method is not very usable as the index does not represent anything specific for the outside world.
func (*CircularList[T]) Head ¶ added in v0.3.3
func (clist *CircularList[T]) Head() T
Head returns the oldest item of the list. In case the list is empty, panic() is caused.
func (*CircularList[T]) Last ¶ added in v0.3.4
func (clist *CircularList[T]) Last() T
Last returns the most recent item of the list. In case the list is empty, panic() is caused.
func (*CircularList[T]) Len ¶ added in v0.3.3
func (clist *CircularList[T]) Len() int
Len returns size of the list
func (*CircularList[T]) Prepend ¶ added in v0.3.8
func (clist *CircularList[T]) Prepend(v T)
func (*CircularList[T]) ShiftUntil ¶ added in v0.3.3
func (clist *CircularList[T]) ShiftUntil(fn func(item T) bool)
ShiftUntil removes old items starting from the oldest one and moving towards newer ones until 'fn' returns true. In case there are no more items to remove, the function will handle this gracefully without errors. This can be used to e.g. clean old log records.
type Comparable ¶ added in v0.5.0
type Comparable interface { // Compare should return: // * x > 0 if this item is greater than the `other`, // * x == 0 if items are equal // * x < 0 if this item is lesser than the `other` Compare(other Comparable) int }
type ConcurrentMap ¶ added in v0.1.3
type ConcurrentMap[K comparable, T any] struct { sync.RWMutex // contains filtered or unexported fields }
func NewConcurrentMap ¶ added in v0.1.3
func NewConcurrentMap[K comparable, T any]() *ConcurrentMap[K, T]
func NewConcurrentMapFrom ¶ added in v0.1.3
func NewConcurrentMapFrom[K comparable, T any](data map[K]T) *ConcurrentMap[K, T]
func NewConcurrentMapFromJSON ¶ added in v0.2.7
func NewConcurrentMapFromJSON[K comparable, T any](data []byte) (*ConcurrentMap[K, T], error)
func (*ConcurrentMap[K, T]) AsMap ¶ added in v0.1.6
func (cm *ConcurrentMap[K, T]) AsMap() map[K]T
AsMap creates a shallow copy of a map wrapped by this ConcurrentMap
func (*ConcurrentMap[K, T]) Delete ¶ added in v0.1.7
func (cm *ConcurrentMap[K, T]) Delete(k K)
func (*ConcurrentMap[K, T]) Filter ¶ added in v0.5.8
func (cm *ConcurrentMap[K, T]) Filter(fn func(k K, v T) bool) *ConcurrentMap[K, T]
func (*ConcurrentMap[K, T]) ForEach ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) ForEach(fn func(k K, v T))
func (*ConcurrentMap[K, T]) Get ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) Get(k K) T
func (*ConcurrentMap[K, T]) GetWithTest ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) GetWithTest(k K) (T, bool)
func (*ConcurrentMap[K, T]) HasKey ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) HasKey(k K) bool
func (*ConcurrentMap[K, T]) Keys ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) Keys() []K
func (*ConcurrentMap[K, T]) Len ¶ added in v0.1.7
func (cm *ConcurrentMap[K, T]) Len() int
Len returns number of key-value pairs stored in the map
func (*ConcurrentMap[K, T]) MarshalJSON ¶ added in v0.2.7
func (cm *ConcurrentMap[K, T]) MarshalJSON() ([]byte, error)
func (*ConcurrentMap[K, T]) Set ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) Set(k K, v T)
func (*ConcurrentMap[K, T]) Update ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) Update(fn func(k K, v T) T)
func (*ConcurrentMap[K, T]) Values ¶ added in v0.1.3
func (cm *ConcurrentMap[K, T]) Values() []T
type Multidict ¶
type Multidict[T any] struct { // contains filtered or unexported fields }
func NewMultidict ¶
type Set ¶
type Set[T constraints.Ordered] struct { // contains filtered or unexported fields }
func NewSet ¶
func NewSet[T constraints.Ordered](values ...T) *Set[T]
func (*Set[T]) ToOrderedSlice ¶
func (set *Set[T]) ToOrderedSlice() []T