Documentation
¶
Overview ¶
Package collection provides generic data structures.
These structures are not intended as complete implementations; they only provide the operations required by official Dogmatiq engines and utilities.
Index ¶
- func Clone[E any, S setptr[E, T], T any](set S) S
- func IsEquivalentSet[E any](a, b Set[E]) bool
- func Subset[E any, S setptr[E, T], T any](set S, pred func(E) bool) S
- func Union[E any, A setptr[E, T], T any](a A, b Set[E]) A
- type Ordered
- type OrderedMap
- func (m *OrderedMap[K, V]) Clear()
- func (m OrderedMap[K, V]) Elements() iter.Seq2[K, V]
- func (m OrderedMap[K, V]) Get(k K) V
- func (m OrderedMap[K, V]) Has(keys ...K) bool
- func (m OrderedMap[K, V]) Keys() iter.Seq[K]
- func (m OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) Remove(keys ...K)
- func (m *OrderedMap[K, V]) Set(k K, v V)
- func (m OrderedMap[K, V]) TryGet(k K) (V, bool)
- func (m OrderedMap[K, V]) Values() iter.Seq[V]
- type OrderedSet
- type Set
- type UnorderedSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsEquivalentSet ¶
IsEquivalentSet returns true if a and b contain the same elements.
Types ¶
type OrderedMap ¶
OrderedMap is an map of keys to values that maintains the order of the keys.
func (*OrderedMap[K, V]) Clear ¶
func (m *OrderedMap[K, V]) Clear()
Clear removes all keys from the map.
func (OrderedMap[K, V]) Elements ¶
func (m OrderedMap[K, V]) Elements() iter.Seq2[K, V]
Elements returns an iterator that yields all the key/value pairs in the map, in key order.
func (OrderedMap[K, V]) Get ¶
func (m OrderedMap[K, V]) Get(k K) V
Get returns the value associated with the given key. It returns the zero value if the key is not in the map.
func (OrderedMap[K, V]) Has ¶
func (m OrderedMap[K, V]) Has(keys ...K) bool
Has returns true if the map contains all of the given keys.
func (OrderedMap[K, V]) Keys ¶
func (m OrderedMap[K, V]) Keys() iter.Seq[K]
Keys returns an iterator that yields all the keys in the map, in order.
func (OrderedMap[K, V]) Len ¶
func (m OrderedMap[K, V]) Len() int
Len returns the number of elements in the map.
func (*OrderedMap[K, V]) Remove ¶
func (m *OrderedMap[K, V]) Remove(keys ...K)
Remove removes all of the given keys from the map.
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(k K, v V)
Set sets the value associated with k to v.
func (OrderedMap[K, V]) TryGet ¶
func (m OrderedMap[K, V]) TryGet(k K) (V, bool)
TryGet returns the value associated with the given key, or false if the key is not in the map.
func (OrderedMap[K, V]) Values ¶
func (m OrderedMap[K, V]) Values() iter.Seq[V]
Values returns an iterator that yields all the values in the map in the order of their keys.
type OrderedSet ¶
type OrderedSet[E Ordered[E]] struct { // contains filtered or unexported fields }
OrderedSet is an ordered set of unique T values.
func NewOrderedSet ¶
func NewOrderedSet[E Ordered[E]](elements ...E) *OrderedSet[E]
NewOrderedSet returns a new OrderedSet containing the given elements.
func (*OrderedSet[E]) Add ¶
func (s *OrderedSet[E]) Add(elements ...E)
Add adds the given elements to the set.
func (*OrderedSet[E]) Clear ¶
func (s *OrderedSet[E]) Clear()
Clear removes all elements from the set.
func (OrderedSet[E]) Elements ¶
func (s OrderedSet[E]) Elements() iter.Seq[E]
Elements returns an iterator that yields all elements in the set, in order.
func (OrderedSet[E]) Has ¶
func (s OrderedSet[E]) Has(elements ...E) bool
Has returns true if the set contains all of the given elements.
func (OrderedSet[E]) Len ¶
func (s OrderedSet[E]) Len() int
Len returns the number of elements in the set.
func (*OrderedSet[E]) Remove ¶
func (s *OrderedSet[E]) Remove(elements ...E)
Remove removes the given elements from the set.
type Set ¶
type Set[E any] interface { Add(...E) Remove(...E) Clear() Has(...E) bool Len() int Elements() iter.Seq[E] }
Set is a collection of unique elements.
type UnorderedSet ¶
type UnorderedSet[E comparable] struct { // contains filtered or unexported fields }
UnorderedSet is an unordered set of unique T values.
func NewUnorderedSet ¶
func NewUnorderedSet[E comparable](elements ...E) *UnorderedSet[E]
NewUnorderedSet returns a new UnorderedSet containing the given elements.
func (*UnorderedSet[E]) Add ¶
func (s *UnorderedSet[E]) Add(elements ...E)
Add adds the given elements to the set.
func (*UnorderedSet[E]) Clear ¶
func (s *UnorderedSet[E]) Clear()
Clear removes all elements from the set.
func (UnorderedSet[E]) Elements ¶
func (s UnorderedSet[E]) Elements() iter.Seq[E]
Elements returns an iterator that yields all elements in the set.
func (UnorderedSet[E]) Has ¶
func (s UnorderedSet[E]) Has(elements ...E) bool
Has returns true if the set contains all of the given elements.
func (UnorderedSet[E]) Len ¶
func (s UnorderedSet[E]) Len() int
Len returns the number of elements in the set.
func (*UnorderedSet[E]) Remove ¶
func (s *UnorderedSet[E]) Remove(elements ...E)
Remove removes the given elements from the set.