Documentation ¶
Index ¶
- func TranslateToMapOf[K comparable, V any, D any](s *SafeMap[K, V], translator func(V) D) map[K]D
- func WithBalancedPartitions(nRoot float64, minimumPartitions int) fifoInitializationOption
- func WithSweepFrequency(frequency time.Duration) fifoInitializationOption
- type FifoMapCache
- func (f *FifoMapCache[K, V]) Capacity() int
- func (f *FifoMapCache[K, V]) Clear()
- func (f *FifoMapCache[K, V]) Contains(key K) bool
- func (f *FifoMapCache[K, V]) Delete(key K)
- func (f *FifoMapCache[K, V]) Get(key K) (value V)
- func (f *FifoMapCache[K, V]) Keys() []K
- func (f *FifoMapCache[K, V]) Len() int
- func (f *FifoMapCache[K, V]) Resize(capacity int)
- func (f *FifoMapCache[K, V]) Set(key K, value V)
- func (f *FifoMapCache[K, V]) Sweep()
- func (f *FifoMapCache[K, V]) Values() []V
- type GenericStack
- type OrderedBTree
- func (t *OrderedBTree[K, V]) Ascend(iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) AscendGreaterOrEqual(pivot K, iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) AscendLessThan(pivot K, iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) AscendRange(greaterThanEqual, lessThan K, iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) Clone() *OrderedBTree[K, V]
- func (t *OrderedBTree[K, V]) Delete(key K) (value *V, ok bool)
- func (t *OrderedBTree[K, V]) DeleteMax() (key K, value *V)
- func (t *OrderedBTree[K, V]) DeleteMin() (key K, value *V)
- func (t *OrderedBTree[K, V]) Descend(iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) DescendGreaterThan(pivot K, iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) DescendLessOrEqual(pivot K, iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) DescendRange(greaterThan, lessThanEqual K, iter func(key K, value *V) bool)
- func (t *OrderedBTree[K, V]) Get(key K) (value *V, ok bool)
- func (t *OrderedBTree[K, V]) Has(key K) bool
- func (t *OrderedBTree[K, V]) Len() int
- func (t *OrderedBTree[K, V]) Max() (key K, value *V)
- func (t *OrderedBTree[K, V]) Min() (key K, value *V)
- func (t *OrderedBTree[K, V]) Set(key K, value *V)
- type SafeMap
- func (s *SafeMap[K, V]) Clear()
- func (s *SafeMap[K, V]) ClearAndResize(newSize int)
- func (s *SafeMap[K, V]) Contains(key K) bool
- func (s *SafeMap[K, V]) CopyToMap() map[K]V
- func (s *SafeMap[K, V]) Delete(key K)
- func (s *SafeMap[K, V]) Get(key K) (value V)
- func (s *SafeMap[K, V]) GetOrAdd(key K, val V) (value V)
- func (s *SafeMap[K, V]) Has(key K) bool
- func (s *SafeMap[K, V]) Keys() []K
- func (s *SafeMap[K, V]) Len() int
- func (s *SafeMap[K, V]) Set(key K, value V)
- func (s *SafeMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func TranslateToMapOf ¶ added in v0.4.10
func TranslateToMapOf[K comparable, V any, D any](s *SafeMap[K, V], translator func(V) D) map[K]D
TranslateToMapOf returns a map of type D from the map of type V
func WithBalancedPartitions ¶
WithBalancedPartitions balances the partitions based upon the nRoot parameter, calculating the number of partitions equal to the Nth root of capacity nRoot should be greater than 1. nRoot of 2 is same as the default number of partitions, which balances the number of values in each partition close to the number of partitions. nRoot less than 2 (greater than 1) will reduce number of partitions, making each partition containing more values. nRoot greater than 2 will increase number of partitions, making each partition contains fewer values. If the calculated number of partitions is less than minimumPartitions, minimumPartitions is used.
func WithSweepFrequency ¶ added in v0.4.7
Types ¶
type FifoMapCache ¶
type FifoMapCache[K comparable, V any] struct { // contains filtered or unexported fields }
func NewFifoMapCache ¶
func NewFifoMapCache[K comparable, V any](ctx context.Context, capacity int, options ...fifoInitializationOption) *FifoMapCache[K, V]
func (*FifoMapCache[K, V]) Capacity ¶ added in v0.4.7
func (f *FifoMapCache[K, V]) Capacity() int
Capacity returns the actual capacity of the map once the number of partitions and the partition capacity are calculated
func (*FifoMapCache[K, V]) Clear ¶ added in v0.4.2
func (f *FifoMapCache[K, V]) Clear()
Clear clears the map
func (*FifoMapCache[K, V]) Contains ¶
func (f *FifoMapCache[K, V]) Contains(key K) bool
Contains returns true if the key of type K is in the map
func (*FifoMapCache[K, V]) Delete ¶
func (f *FifoMapCache[K, V]) Delete(key K)
func (*FifoMapCache[K, V]) Get ¶
func (f *FifoMapCache[K, V]) Get(key K) (value V)
Get returns the value of type V for the key of type K. If the key is not found, the zero value of V is returned.
func (*FifoMapCache[K, V]) Keys ¶ added in v0.4.2
func (f *FifoMapCache[K, V]) Keys() []K
Keys returns a slice of keys
func (*FifoMapCache[K, V]) Len ¶
func (f *FifoMapCache[K, V]) Len() int
Len returns the length of the map
func (*FifoMapCache[K, V]) Resize ¶ added in v0.4.4
func (f *FifoMapCache[K, V]) Resize(capacity int)
func (*FifoMapCache[K, V]) Set ¶
func (f *FifoMapCache[K, V]) Set(key K, value V)
Set sets the value of type V for the key of type K.
func (*FifoMapCache[K, V]) Sweep ¶ added in v0.4.7
func (f *FifoMapCache[K, V]) Sweep()
sweep removes partitions from the stack if the number of partitions exceeds the maxPartitions
func (*FifoMapCache[K, V]) Values ¶ added in v0.4.2
func (f *FifoMapCache[K, V]) Values() []V
Values returns a slice of values
type GenericStack ¶
type GenericStack[T any] struct { // contains filtered or unexported fields }
func NewGenericStack ¶
func NewGenericStack[T any](initialSize int) *GenericStack[T]
NewGenericStack returns an initialized reference to a GenericStack of T
func (*GenericStack[T]) Len ¶
func (s *GenericStack[T]) Len() int
Len returns the number of elements on the stack
func (*GenericStack[T]) Peek ¶
func (s *GenericStack[T]) Peek(id uint64) (value T, err error)
Peek returns the value on the stack that was assigned the id requested. IDNotFoundError returned if id not found.
func (*GenericStack[T]) Pop ¶
func (s *GenericStack[T]) Pop() T
Pop removes the next T from the stack and returns it
func (*GenericStack[T]) Push ¶
func (s *GenericStack[T]) Push(value T) (id uint64)
Push pushes value of type T on the stack, returning the assigned id in the stack
func (*GenericStack[T]) Values ¶ added in v0.4.2
func (s *GenericStack[T]) Values() []T
Values returns a slice of all the values on the stack
type OrderedBTree ¶ added in v0.4.7
type OrderedBTree[K cmp.Ordered, V any] struct { *btree.BTree // contains filtered or unexported fields }
OrderedBTree is a thread-safe implementation of a BTree that supports ordered types. It is a wrapper around the google/btree package.
func NewOrderedBTree ¶ added in v0.4.7
func NewOrderedBTree[K cmp.Ordered, V any]() *OrderedBTree[K, V]
NewOrderedBTree returns an initialized reference to an OrderedBTree of K and V
func (*OrderedBTree[K, V]) Ascend ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Ascend(iter func(key K, value *V) bool)
Ascend calls the iter function for every key/value pair in the BTree in ascending order.
func (*OrderedBTree[K, V]) AscendGreaterOrEqual ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) AscendGreaterOrEqual(pivot K, iter func(key K, value *V) bool)
AscendGreaterOrEqual calls the iter function for every key/value pair in the BTree in ascending order starting with the first key/value pair that is greater than or equal to the pivot key.
func (*OrderedBTree[K, V]) AscendLessThan ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) AscendLessThan(pivot K, iter func(key K, value *V) bool)
AscendGreaterThan calls the iter function for every key/value pair in the BTree, starting with the Min value up to the pivot key..
func (*OrderedBTree[K, V]) AscendRange ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) AscendRange(greaterThanEqual, lessThan K, iter func(key K, value *V) bool)
AscendRange calls the iter function for every key/value pair in the BTree, starting with the first key/value pair that is greater than or equal to the greaterThanEqual key up to the first key/value pair that is less than the lessThan key.
func (*OrderedBTree[K, V]) Clone ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Clone() *OrderedBTree[K, V]
Clone returns a copy of the BTree
func (*OrderedBTree[K, V]) Delete ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Delete(key K) (value *V, ok bool)
Delete deletes the key of type K. If the key is not found, ok is returned as false.
func (*OrderedBTree[K, V]) DeleteMax ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) DeleteMax() (key K, value *V)
DeleteMax deletes the maximum key and value in the BTree
func (*OrderedBTree[K, V]) DeleteMin ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) DeleteMin() (key K, value *V)
DeleteMin deletes the minimum key and value in the BTree
func (*OrderedBTree[K, V]) Descend ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Descend(iter func(key K, value *V) bool)
Descend calls the iter function for every key/value pair in the BTree in descending order.
func (*OrderedBTree[K, V]) DescendGreaterThan ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) DescendGreaterThan(pivot K, iter func(key K, value *V) bool)
DescendLessOrEqual calls the iterator for every value in the tree within the range [pivot, first], until iterator returns false
func (*OrderedBTree[K, V]) DescendLessOrEqual ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) DescendLessOrEqual(pivot K, iter func(key K, value *V) bool)
DDescendGreaterThan calls the iterator for every value in the tree within the range [last, pivot), until iterator returns false
func (*OrderedBTree[K, V]) DescendRange ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) DescendRange(greaterThan, lessThanEqual K, iter func(key K, value *V) bool)
DescendRange calls the iterator for every value in the tree within the range [lessOrEqual, greaterThan), until iterator returns false
func (*OrderedBTree[K, V]) Get ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Get(key K) (value *V, ok bool)
Get returns the value of type V for the key of type K. If the key is not found, ok is returned as false.
func (*OrderedBTree[K, V]) Has ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Has(key K) bool
Has returns true if the key of type K exists in the BTree.
func (*OrderedBTree[K, V]) Len ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Len() int
Len returns the length of the BTree
func (*OrderedBTree[K, V]) Max ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Max() (key K, value *V)
Max returns the maximum key and value in the BTree
func (*OrderedBTree[K, V]) Min ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Min() (key K, value *V)
Min returns the minimum key and value in the BTree
func (*OrderedBTree[K, V]) Set ¶ added in v0.4.7
func (t *OrderedBTree[K, V]) Set(key K, value *V)
Set sets the value of type V for the key of type K.
type SafeMap ¶
type SafeMap[K comparable, V any] struct { // contains filtered or unexported fields }
SafeMap wraps a map[K]V with a simple RWMutex to facilitate concurrency
func NewSafeMap ¶
func NewSafeMap[K comparable, V any](initialCapacity int) *SafeMap[K, V]
NewSafeMap returns an initialized reference to a SafeMap of K, V
func (*SafeMap[K, V]) Clear ¶ added in v0.4.11
func (s *SafeMap[K, V]) Clear()
Clear removes all the keys and values from the map
func (*SafeMap[K, V]) ClearAndResize ¶ added in v0.4.11
ClearAndResize clears the map and resize it to the new size
func (*SafeMap[K, V]) CopyToMap ¶ added in v0.4.10
func (s *SafeMap[K, V]) CopyToMap() map[K]V
CopyToMap returns a copy of the map
func (*SafeMap[K, V]) Delete ¶
func (s *SafeMap[K, V]) Delete(key K)
Delete deletes the key of type K from the map
func (*SafeMap[K, V]) Get ¶
func (s *SafeMap[K, V]) Get(key K) (value V)
Get returns the value of type V for the key of type K. If the key is not found, the zero value of V is returned.
func (*SafeMap[K, V]) GetOrAdd ¶ added in v0.4.10
func (s *SafeMap[K, V]) GetOrAdd(key K, val V) (value V)
GetOrAdd returns the value of type V for the key of type K. If the key is not found, the value is added to the map and returned.
func (*SafeMap[K, V]) Keys ¶ added in v0.4.2
func (s *SafeMap[K, V]) Keys() []K
Keys returns a slice of all the keys in the map