Documentation
¶
Overview ¶
Package set implements a generic programmatic Set data container.
Index ¶
- Variables
- type Config
- type Set
- func (set *Set[K, H, T]) Clone() *Set[K, H, T]
- func (set *Set[K, H, T]) Contains(key K) bool
- func (set *Set[K, H, T]) Copy(dst *Set[K, H, T], cond func(T) bool) *Set[K, H, T]
- func (set *Set[K, H, T]) ForEach(fn func(T) bool)
- func (set *Set[K, H, T]) Get(key K) (T, error)
- func (set *Set[K, H, T]) Pop(key K) (T, error)
- func (set *Set[K, H, T]) Push(value T) (T, error)
- func (set *Set[K, H, T]) Reset() error
- func (set *Set[K, H, T]) Values() []T
Constants ¶
This section is empty.
Variables ¶
var ( // ErrExist is returned by Set.Push when a matching entry is // already present. ErrExist = core.ErrExists // ErrNotExist is returned by Set.Pop and Set.Get when a matching entry // is not present. ErrNotExist = core.ErrNotExists )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[K, H comparable, T any] struct { // Hash computes the bucket identifier for the given K type Hash func(k K) (H, error) // ItemKey computes the K value from the T instance ItemKey func(v T) (K, error) // ItemMatch confirms the T instance matches the K value ItemMatch func(k K, v T) bool }
Config defines the callbacks used by a Set.
func (Config[K, H, T]) Equal ¶ added in v0.1.4
Equal determines if two Config instances use exactly the same callback functions by comparing their memory addresses using reflection. This is used to optimize Set operations like Copy() when configs are identical.
Equal isn't cheap but it saves Copy() from performing unnecessary rehashing.
func (Config[K, H, T]) Init ¶
Init initializes a Set that wasn't created using Config.New.
type Set ¶
type Set[K, H comparable, T any] struct { // contains filtered or unexported fields }
Set implements a simple set using generics.
func (*Set[K, H, T]) Contains ¶ added in v0.1.2
Contains tells if there is a matching item in the Set. It returns false if: - the Set is nil or uninitialized - the key is invalid according to the Set's configuration - no matching item exists.
func (*Set[K, H, T]) Copy ¶
Copy copies the values in the Set to another, optionally using a condition function.
If no destination is provided, one will be created. If an uninitialized destination is provided, it will be initialized using the source's Config and values copied in bulk.
func (*Set[K, H, T]) ForEach ¶
ForEach calls a function for each value in the Set until it returns false.
func (*Set[K, H, T]) Push ¶
Push adds entries to the set unless it already exist. It returns the value with matching key stored in the Set so it can be treated as a global reference.