Documentation ¶
Index ¶
- func ForEachChunk[T any](data []T, chunkSize uint16, handler func(items []T))
- type MultiMap
- func (mm *MultiMap[T, Q]) Add(key T, item Q)
- func (mm *MultiMap[T, Q]) AsReadOnly() ReadOnlyMultimap[T, Q]
- func (mm *MultiMap[T, Q]) Clear()
- func (mm *MultiMap[T, Q]) Get(key T) ([]Q, bool)
- func (mm *MultiMap[T, Q]) Has(key T) bool
- func (mm *MultiMap[T, Q]) IsEmpty() bool
- func (mm *MultiMap[T, Q]) Keys() []T
- func (mm *MultiMap[T, Q]) Len() int
- func (mm *MultiMap[T, Q]) RemoveKey(key T)
- func (mm MultiMap[T, Q]) Values() []Q
- type ReadOnlyMultimap
- type Set
- func (s *Set[T]) Add(value T) bool
- func (s *Set[T]) AsSlice() []T
- func (s *Set[T]) Copy() *Set[T]
- func (s *Set[T]) Extend(values []T)
- func (s *Set[T]) ForEach(callback func(value T) error) error
- func (s *Set[T]) Has(value T) bool
- func (s *Set[T]) Intersect(other *Set[T]) *Set[T]
- func (s *Set[T]) IntersectionDifference(other *Set[T]) *Set[T]
- func (s *Set[T]) IsEmpty() bool
- func (s *Set[T]) Len() int
- func (s *Set[T]) Remove(value T) bool
- func (s *Set[T]) RemoveAll(other *Set[T])
- func (s *Set[T]) Subtract(other *Set[T]) *Set[T]
- type StringSetWrapper
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ForEachChunk ¶
ForEachChunk executes the given handler for each chunk of items in the slice.
Types ¶
type MultiMap ¶
type MultiMap[T comparable, Q any] struct { // contains filtered or unexported fields }
MultiMap represents a map that can contain 1 or more values for each key.
func NewMultiMap ¶
func NewMultiMap[T comparable, Q any]() *MultiMap[T, Q]
NewMultiMap creates and returns a new MultiMap from keys of type T to values of type Q.
func (*MultiMap[T, Q]) Add ¶
func (mm *MultiMap[T, Q]) Add(key T, item Q)
Add adds the value to the map for the given key. If there exists an existing value, then this value is added to those already present *without comparison*. This means a value can be added twice, if this method is called again for the same value.
func (*MultiMap[T, Q]) AsReadOnly ¶ added in v1.16.0
func (mm *MultiMap[T, Q]) AsReadOnly() ReadOnlyMultimap[T, Q]
AsReadOnly returns a read-only *copy* of the mulitmap.
func (*MultiMap[T, Q]) Clear ¶
func (mm *MultiMap[T, Q]) Clear()
Clear clears all entries in the map.
func (*MultiMap[T, Q]) Get ¶
Get returns the values for the given key in the map and whether the key existed. If the key does not exist, an empty slice is returned.
func (*MultiMap[T, Q]) Keys ¶
func (mm *MultiMap[T, Q]) Keys() []T
Keys returns the keys of the map.
type ReadOnlyMultimap ¶ added in v1.16.0
type ReadOnlyMultimap[T comparable, Q any] interface { // Has returns true if the key is found in the map. Has(key T) bool // Get returns the values for the given key in the map and whether the key existed. If the key // does not exist, an empty slice is returned. Get(key T) ([]Q, bool) // IsEmpty returns true if the map is currently empty. IsEmpty() bool // Len returns the length of the map, e.g. the number of *keys* present. Len() int // Keys returns the keys of the map. Keys() []T // Values returns all values in the map. Values() []Q }
ReadOnlyMultimap is a read-only version of the multimap.
type Set ¶
type Set[T comparable] struct { // contains filtered or unexported fields }
Set implements a very basic generic set.
func (*Set[T]) Add ¶
Add adds the given value to the set and returns true. If the value is already present, returns false.
func (*Set[T]) AsSlice ¶
func (s *Set[T]) AsSlice() []T
AsSlice returns the set as a slice of values.
func (*Set[T]) ForEach ¶
ForEach executes the callback for each item in the set until an error is encountered.
func (*Set[T]) Intersect ¶
Intersect removes any values from this set that are not shared with the other set, returning a new set.
func (*Set[T]) IntersectionDifference ¶
IntersectionDifference removes any values from this set that are not shared with the other set. Returns the same set.
func (*Set[T]) Remove ¶
Remove removes the value from the set, returning whether the element was present when the call was made.
type StringSetWrapper ¶
StringSetWrapper wraps a set of strings and provides marshalling for zerolog.
func StringSet ¶
func StringSet(set *Set[string]) StringSetWrapper
StringSet wraps a Set of strings and provides automatic log marshalling.
func (StringSetWrapper) MarshalZerologObject ¶
func (s StringSetWrapper) MarshalZerologObject(e *zerolog.Event)
MarshalZerologObject implements zerolog object marshalling.