Documentation
¶
Index ¶
- type CounterSet
- type Set
- func (s Set[T]) Add(val T) bool
- func (s Set[T]) Clone() Set[T]
- func (s Set[T]) Contains(val T) bool
- func (s Set[T]) Keys() []T
- func (s Set[T]) Merge(other Set[T])
- func (s Set[T]) Remove(val T)
- func (s Set[T]) Set(val T)
- func (s Set[T]) SetAll(vals []T)
- func (s Set[T]) Sorted(less func(a, b T) int) []T
- type StringCounterSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CounterSet ¶
type CounterSet[T comparable] map[T]int
A CounterSet is map with keys of type T and values representing a count. The Increment() function is used to change the count value. A CounterSet it is not safe for concurrency and its order is not guaranteed.
func (CounterSet[T]) Increment ¶
func (s CounterSet[T]) Increment(key T, cnt int) (int, int, bool)
Increment increments the CounterSet value for 'key' by 'cnt' and returns the old and new value. The bool returns true if the key was pre-existing. Negative cnt values are ok. Increment is not safe for concurrency.
func (CounterSet[T]) Reset ¶
func (s CounterSet[T]) Reset(key T)
Reset resets the CounterSet value for 'key' to 0. If the key is not present in the map, it is added and set to 0. Reset is not safe for concurrency.
func (CounterSet[T]) Value ¶
func (s CounterSet[T]) Value(key T) (int, bool)
Value returns the value for the provided key, or false if it doesn't exist.
type Set ¶
type Set[T comparable] map[T]struct{}
Set is a collection of unique elements
func (Set[T]) Add ¶
Add inserts a value into the Set if does not already exist. True is returned only if the value was inserted.
func (Set[T]) Keys ¶
func (s Set[T]) Keys() []T
Keys returns the set elements as a slice in an unpredictable order.
type StringCounterSet ¶
type StringCounterSet = CounterSet[string]
StringCounterSet is CounterSet with string keys
func NewStringCounterSet ¶
func NewStringCounterSet() StringCounterSet
NewStringCounterSet returns a new StringCounterSet
func NewStringCounterSetCap ¶
func NewStringCounterSetCap(capacity int) StringCounterSet
NewStringCounterSetCap returns a new StringCounterSet with a capacity set.