Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var NewStringSet = NewSet[string] // nolint:gochecknoglobals
NewStringSet and StringSet are Aliases.
var Time timing // nolint:gochecknoglobals
Functions ¶
Types ¶
type DefaultMap ¶
type DefaultMap[K comparable, V any] struct { // Map is a delegate. // All methods are embedded which grants the same capabilities, plus default value. Map[K, V] // contains filtered or unexported fields }
DefaultMap wrapper of the map that allows setting default return value on missing keys.
func NewDefaultMap ¶
func NewDefaultMap[K comparable, V any](dict Map[K, V], fallback func(K) V) DefaultMap[K, V]
func (DefaultMap[K, V]) Get ¶
func (m DefaultMap[K, V]) Get(key K) V
Get method uses map with a fallback value.
type IndexedLists ¶
type IndexedLists[ID comparable, V any] map[ID][]V
IndexedLists is a dynamic list of identifiable slices. Each slice is associated to the unique comparable object.
func (IndexedLists[ID, V]) Add ¶
func (l IndexedLists[ID, V]) Add(bucket ID, objects ...V)
Add objects into the named list. If the list didn't exist it will create it.
func (IndexedLists[ID, V]) GetBuckets ¶
func (l IndexedLists[ID, V]) GetBuckets() []ID
GetBuckets returns names of lists, buckets they are in. Example:
veggies: cucumber, tomato; fruits: pineapple;
Will return veggies and fruits.
type Map ¶
type Map[K comparable, V any] map[K]V
Map is a generic version of map with useful methods. It can return Keys as a slice or a Set.
type NamedLists ¶
type NamedLists[V any] IndexedLists[string, V]
NamedLists is a collection of lists each having a string name.
func (NamedLists[V]) Add ¶
func (l NamedLists[V]) Add(bucket string, objects ...V)
func (NamedLists[V]) GetBuckets ¶
func (l NamedLists[V]) GetBuckets() []string
type Set ¶
type Set[T comparable] map[T]struct{}
Set data structure that can hold any type of data.
func NewSet ¶
func NewSet[V comparable](values ...V) Set[V]
NewSet creates a set from multiple values.
func NewSetFromList ¶
func NewSetFromList[V comparable](values []V) Set[V]
NewSetFromList creates a set from slice.
func (Set[T]) Add ¶
func (s Set[T]) Add(values []T)
Add will add a list of values to the unique set. Repetitions will be omitted.
func (Set[T]) AddOne ¶
func (s Set[T]) AddOne(value T)
AddOne will add single value to the unique set.
type UniqueLists ¶
type UniqueLists[ID, V comparable] map[ID]Set[V]
UniqueLists is a collection of Sets each associated to identifier.
func (UniqueLists[ID, V]) Add ¶
func (l UniqueLists[ID, V]) Add(bucket ID, objects ...V)
func (UniqueLists[ID, V]) GetBuckets ¶
func (l UniqueLists[ID, V]) GetBuckets() []ID