Documentation
¶
Overview ¶
Package maps provides generic map data structures.
These structures are not intended for general use; they only provide the operations required by official Dogmatiq engines and utilities.
Index ¶
- type Map
- func (m *Map[K, V]) All() iter.Seq2[K, V]
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Clone() *Map[K, V]
- func (m *Map[K, V]) Get(k K) V
- func (m *Map[K, V]) Has(keys ...K) bool
- func (m *Map[K, V]) Keys() iter.Seq[K]
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Merge(x *Map[K, V]) *Map[K, V]
- func (m *Map[K, V]) Project(transform func(K, V) (K, V, bool)) *Map[K, V]
- func (m *Map[K, V]) Remove(keys ...K)
- func (m *Map[K, V]) Select(pred func(K, V) bool) *Map[K, V]
- func (m *Map[K, V]) Set(k K, v V)
- func (m *Map[K, V]) TryGet(k K) (V, bool)
- func (m *Map[K, V]) Values() iter.Seq[V]
- type Ordered
- func (m *Ordered[K, V]) All() iter.Seq2[K, V]
- func (m *Ordered[K, V]) Clear()
- func (m *Ordered[K, V]) Clone() *Ordered[K, V]
- func (m *Ordered[K, V]) Get(k K) V
- func (m *Ordered[K, V]) Has(keys ...K) bool
- func (m *Ordered[K, V]) Keys() iter.Seq[K]
- func (m *Ordered[K, V]) Len() int
- func (m *Ordered[K, V]) Merge(x *Ordered[K, V]) *Ordered[K, V]
- func (m *Ordered[K, V]) Project(transform func(K, V) (K, V, bool)) *Ordered[K, V]
- func (m *Ordered[K, V]) Remove(keys ...K)
- func (m *Ordered[K, V]) Reverse() iter.Seq2[K, V]
- func (m *Ordered[K, V]) ReverseKeys() iter.Seq[K]
- func (m *Ordered[K, V]) ReverseValues() iter.Seq[V]
- func (m *Ordered[K, V]) Select(pred func(K, V) bool) *Ordered[K, V]
- func (m *Ordered[K, V]) Set(k K, v V)
- func (m *Ordered[K, V]) TryGet(k K) (V, bool)
- func (m *Ordered[K, V]) Values() iter.Seq[V]
- type OrderedByComparator
- func (m *OrderedByComparator[K, V, C]) All() iter.Seq2[K, V]
- func (m *OrderedByComparator[K, V, C]) Clear()
- func (m *OrderedByComparator[K, V, C]) Clone() *OrderedByComparator[K, V, C]
- func (m *OrderedByComparator[K, V, C]) Get(k K) V
- func (m *OrderedByComparator[K, V, C]) Has(keys ...K) bool
- func (m *OrderedByComparator[K, V, C]) Keys() iter.Seq[K]
- func (m *OrderedByComparator[K, V, C]) Len() int
- func (m *OrderedByComparator[K, V, C]) Merge(x *OrderedByComparator[K, V, C]) *OrderedByComparator[K, V, C]
- func (m *OrderedByComparator[K, V, C]) Project(transform func(K, V) (K, V, bool)) *OrderedByComparator[K, V, C]
- func (m *OrderedByComparator[K, V, C]) Remove(keys ...K)
- func (m *OrderedByComparator[K, V, C]) Reverse() iter.Seq2[K, V]
- func (m *OrderedByComparator[K, V, C]) ReverseKeys() iter.Seq[K]
- func (m *OrderedByComparator[K, V, C]) ReverseValues() iter.Seq[V]
- func (m *OrderedByComparator[K, V, C]) Select(pred func(K, V) bool) *OrderedByComparator[K, V, C]
- func (m *OrderedByComparator[K, V, C]) Set(k K, v V)
- func (m *OrderedByComparator[K, V, C]) TryGet(k K) (V, bool)
- func (m *OrderedByComparator[K, V, C]) Values() iter.Seq[V]
- type OrderedByKey
- func (m *OrderedByKey[K, V]) All() iter.Seq2[K, V]
- func (m *OrderedByKey[K, V]) Clear()
- func (m *OrderedByKey[K, V]) Clone() *OrderedByKey[K, V]
- func (m *OrderedByKey[K, V]) Get(k K) V
- func (m *OrderedByKey[K, V]) Has(keys ...K) bool
- func (m *OrderedByKey[K, V]) Keys() iter.Seq[K]
- func (m *OrderedByKey[K, V]) Len() int
- func (m *OrderedByKey[K, V]) Merge(x *OrderedByKey[K, V]) *OrderedByKey[K, V]
- func (m *OrderedByKey[K, V]) Project(transform func(K, V) (K, V, bool)) *OrderedByKey[K, V]
- func (m *OrderedByKey[K, V]) Remove(keys ...K)
- func (m *OrderedByKey[K, V]) Reverse() iter.Seq2[K, V]
- func (m *OrderedByKey[K, V]) ReverseKeys() iter.Seq[K]
- func (m *OrderedByKey[K, V]) ReverseValues() iter.Seq[V]
- func (m *OrderedByKey[K, V]) Select(pred func(K, V) bool) *OrderedByKey[K, V]
- func (m *OrderedByKey[K, V]) Set(k K, v V)
- func (m *OrderedByKey[K, V]) TryGet(k K) (V, bool)
- func (m *OrderedByKey[K, V]) Values() iter.Seq[V]
- type Pair
- type Proto
- func (m *Proto[K, V]) All() iter.Seq2[K, V]
- func (m *Proto[K, V]) Clear()
- func (m *Proto[K, V]) Clone() *Proto[K, V]
- func (m *Proto[K, V]) Get(k K) V
- func (m *Proto[K, V]) Has(keys ...K) bool
- func (m *Proto[K, V]) Keys() iter.Seq[K]
- func (m *Proto[K, V]) Len() int
- func (m *Proto[K, V]) Merge(x *Proto[K, V]) *Proto[K, V]
- func (m *Proto[K, V]) Project(transform func(K, V) (K, V, bool)) *Proto[K, V]
- func (m *Proto[K, V]) Remove(keys ...K)
- func (m *Proto[K, V]) Select(pred func(K, V) bool) *Proto[K, V]
- func (m *Proto[K, V]) Set(k K, v V)
- func (m *Proto[K, V]) TryGet(k K) (V, bool)
- func (m *Proto[K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is an unordered map of keys of type K to values of type V.
It provides the common interface implemented by all map types in this package to Go's built-in map type.
func New ¶
func New[K comparable, V any](pairs ...Pair[K, V]) *Map[K, V]
New returns a Map containing the given key/value pairs.
func NewFromSeq ¶ added in v0.16.0
func NewFromSeq[K comparable, V any](seq iter.Seq2[K, V]) *Map[K, V]
NewFromSeq returns a Map containing the key/value pairs from the given sequence.
func (*Map[K, V]) All ¶
All returns a sequence that yields all key/value pairs in the map in no particular order.
func (*Map[K, V]) Get ¶
func (m *Map[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 (*Map[K, V]) Keys ¶
Keys returns a sequence that yields all keys in the map in no particular order.
func (*Map[K, V]) Merge ¶
Merge returns a new map containing all key/value pairs from s and x.
If a key is present in both maps, the value from x is used.
func (*Map[K, V]) Project ¶
Project constructs a new map by applying the given transform function to each key/value pair in the map. If the transform function returns false, the key is omitted from the resulting map.
func (*Map[K, V]) Remove ¶
func (m *Map[K, V]) Remove(keys ...K)
Remove removes the given keys from the map.
func (*Map[K, V]) Select ¶
Select returns a new map containing all key/value pairs from m for which the given predicate returns true.
func (*Map[K, V]) Set ¶
func (m *Map[K, V]) Set(k K, v V)
Set sets the value associated with the given key.
type Ordered ¶
Ordered is an ordered map of keys of type K to values of type V.
func NewOrdered ¶
NewOrdered returns an Ordered containing the given key/value pairs.
func NewOrderedFromSeq ¶ added in v0.16.0
NewOrderedFromSeq returns an Ordered containing the key/value pairs yielded by the given sequence.
func (*Ordered[K, V]) All ¶
All returns a sequence that yields all key/value pairs in the map in order.
func (*Ordered[K, V]) Get ¶
func (m *Ordered[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 (*Ordered[K, V]) Merge ¶
Merge returns a new map containing all key/value pairs from s and x.
If a key is present in both maps, the value from x is used.
func (*Ordered[K, V]) Project ¶
Project constructs a new map by applying the given transform function to each key/value pair in the map. If the transform function returns false, the key is omitted from the resulting map.
func (*Ordered[K, V]) Remove ¶
func (m *Ordered[K, V]) Remove(keys ...K)
Remove removes the given keys from the map.
func (*Ordered[K, V]) Reverse ¶
Reverse returns a sequence that yields all key/value pairs in the map in reverse order.
func (*Ordered[K, V]) ReverseKeys ¶
ReverseKeys returns a sequence that yields all keys in the map in reverse order.
func (*Ordered[K, V]) ReverseValues ¶
ReverseValues returns a sequence that yields all values in the map in reverse order.
func (*Ordered[K, V]) Select ¶
Select returns a new map containing all key/value pairs from m for which the given predicate returns true.
func (*Ordered[K, V]) Set ¶
func (m *Ordered[K, V]) Set(k K, v V)
Set sets the value associated with the given key.
type OrderedByComparator ¶
type OrderedByComparator[K, V any, C constraints.Comparator[K]] struct { // contains filtered or unexported fields }
OrderedByComparator is an an ordered map of keys of type K to values of type V with ordering defined by a separate comparitor type.
func NewOrderedByComparator ¶
func NewOrderedByComparator[K, V any, C constraints.Comparator[K]](pairs ...Pair[K, V]) *OrderedByComparator[K, V, C]
NewOrderedByComparator returns an OrderedByComparator containing the given key/value pairs.
func NewOrderedByComparatorFromSeq ¶ added in v0.16.0
func NewOrderedByComparatorFromSeq[K, V any, C constraints.Comparator[K]](seq iter.Seq2[K, V]) *OrderedByComparator[K, V, C]
NewOrderedByComparatorFromSeq returns an OrderedByComparator containing the key/value pairs yielded by the given sequence.
func (*OrderedByComparator[K, V, C]) All ¶
func (m *OrderedByComparator[K, V, C]) All() iter.Seq2[K, V]
All returns a sequence that yields all key/value pairs in the map in order.
func (*OrderedByComparator[K, V, C]) Clear ¶
func (m *OrderedByComparator[K, V, C]) Clear()
Clear removes all keys from the map.
func (*OrderedByComparator[K, V, C]) Clone ¶
func (m *OrderedByComparator[K, V, C]) Clone() *OrderedByComparator[K, V, C]
Clone returns a shallow copy of the map.
func (*OrderedByComparator[K, V, C]) Get ¶
func (m *OrderedByComparator[K, V, C]) 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 (*OrderedByComparator[K, V, C]) Has ¶
func (m *OrderedByComparator[K, V, C]) Has(keys ...K) bool
Has returns true if all of the given keys are in the map.
func (*OrderedByComparator[K, V, C]) Keys ¶
func (m *OrderedByComparator[K, V, C]) Keys() iter.Seq[K]
Keys returns a sequence that yields all keys in the map in order.
func (*OrderedByComparator[K, V, C]) Len ¶
func (m *OrderedByComparator[K, V, C]) Len() int
Len returns the number of elements in the map.
func (*OrderedByComparator[K, V, C]) Merge ¶
func (m *OrderedByComparator[K, V, C]) Merge(x *OrderedByComparator[K, V, C]) *OrderedByComparator[K, V, C]
Merge returns a new map containing all key/value pairs from s and x.
If a key is present in both maps, the value from x is used.
func (*OrderedByComparator[K, V, C]) Project ¶
func (m *OrderedByComparator[K, V, C]) Project(transform func(K, V) (K, V, bool)) *OrderedByComparator[K, V, C]
Project constructs a new map by applying the given transform function to each key/value pair in the map. If the transform function returns false, the key is omitted from the resulting map.
func (*OrderedByComparator[K, V, C]) Remove ¶
func (m *OrderedByComparator[K, V, C]) Remove(keys ...K)
Remove removes the given keys from the map.
func (*OrderedByComparator[K, V, C]) Reverse ¶
func (m *OrderedByComparator[K, V, C]) Reverse() iter.Seq2[K, V]
Reverse returns a sequence that yields all key/value pairs in the map in reverse order.
func (*OrderedByComparator[K, V, C]) ReverseKeys ¶
func (m *OrderedByComparator[K, V, C]) ReverseKeys() iter.Seq[K]
ReverseKeys returns a sequence that yields all keys in the map in reverse order.
func (*OrderedByComparator[K, V, C]) ReverseValues ¶
func (m *OrderedByComparator[K, V, C]) ReverseValues() iter.Seq[V]
ReverseValues returns a sequence that yields all values in the map in reverse order.
func (*OrderedByComparator[K, V, C]) Select ¶
func (m *OrderedByComparator[K, V, C]) Select(pred func(K, V) bool) *OrderedByComparator[K, V, C]
Select returns a new map containing all key/value pairs from m for which the given predicate returns true.
func (*OrderedByComparator[K, V, C]) Set ¶
func (m *OrderedByComparator[K, V, C]) Set(k K, v V)
Set sets the value associated with the given key.
func (*OrderedByComparator[K, V, C]) TryGet ¶
func (m *OrderedByComparator[K, V, C]) 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 (*OrderedByComparator[K, V, C]) Values ¶
func (m *OrderedByComparator[K, V, C]) Values() iter.Seq[V]
Values returns a sequence that yields all values in the map in order.
type OrderedByKey ¶
type OrderedByKey[K constraints.Ordered[K], V any] struct { // contains filtered or unexported fields }
OrderedByKey is an an ordered map of keys of type K to values of type V with ordering defined by the K.Compare method.
func NewOrderedByKey ¶
func NewOrderedByKey[K constraints.Ordered[K], V any](pairs ...Pair[K, V]) *OrderedByKey[K, V]
NewOrderedByKey returns an OrderedByKey containing the given key/value pairs.
func NewOrderedByKeyFromSeq ¶ added in v0.16.0
func NewOrderedByKeyFromSeq[K constraints.Ordered[K], V any](seq iter.Seq2[K, V]) *OrderedByKey[K, V]
NewOrderedByKeyFromSeq returns an OrderedByKey containing the key/value pairs yielded by the given sequence.
func (*OrderedByKey[K, V]) All ¶
func (m *OrderedByKey[K, V]) All() iter.Seq2[K, V]
All returns a sequence that yields all key/value pairs in the map in order.
func (*OrderedByKey[K, V]) Clear ¶
func (m *OrderedByKey[K, V]) Clear()
Clear removes all keys from the map.
func (*OrderedByKey[K, V]) Clone ¶
func (m *OrderedByKey[K, V]) Clone() *OrderedByKey[K, V]
Clone returns a shallow copy of the map.
func (*OrderedByKey[K, V]) Get ¶
func (m *OrderedByKey[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 (*OrderedByKey[K, V]) Has ¶
func (m *OrderedByKey[K, V]) Has(keys ...K) bool
Has returns true if all of the given keys are in the map.
func (*OrderedByKey[K, V]) Keys ¶
func (m *OrderedByKey[K, V]) Keys() iter.Seq[K]
Keys returns a sequence that yields all keys in the map in order.
func (*OrderedByKey[K, V]) Len ¶
func (m *OrderedByKey[K, V]) Len() int
Len returns the number of elements in the map.
func (*OrderedByKey[K, V]) Merge ¶
func (m *OrderedByKey[K, V]) Merge(x *OrderedByKey[K, V]) *OrderedByKey[K, V]
Merge returns a new map containing all key/value pairs from s and x.
If a key is present in both maps, the value from x is used.
func (*OrderedByKey[K, V]) Project ¶
func (m *OrderedByKey[K, V]) Project(transform func(K, V) (K, V, bool)) *OrderedByKey[K, V]
Project constructs a new map by applying the given transform function to each key/value pair in the map. If the transform function returns false, the key is omitted from the resulting map.
func (*OrderedByKey[K, V]) Remove ¶
func (m *OrderedByKey[K, V]) Remove(keys ...K)
Remove removes the given keys from the map.
func (*OrderedByKey[K, V]) Reverse ¶
func (m *OrderedByKey[K, V]) Reverse() iter.Seq2[K, V]
Reverse returns a sequence that yields all key/value pairs in the map in reverse order.
func (*OrderedByKey[K, V]) ReverseKeys ¶
func (m *OrderedByKey[K, V]) ReverseKeys() iter.Seq[K]
ReverseKeys returns a sequence that yields all keys in the map in reverse order.
func (*OrderedByKey[K, V]) ReverseValues ¶
func (m *OrderedByKey[K, V]) ReverseValues() iter.Seq[V]
ReverseValues returns a sequence that yields all values in the map in reverse order.
func (*OrderedByKey[K, V]) Select ¶
func (m *OrderedByKey[K, V]) Select(pred func(K, V) bool) *OrderedByKey[K, V]
Select returns a new map containing all key/value pairs from m for which the given predicate returns true.
func (*OrderedByKey[K, V]) Set ¶
func (m *OrderedByKey[K, V]) Set(k K, v V)
Set sets the value associated with the given key.
func (*OrderedByKey[K, V]) TryGet ¶
func (m *OrderedByKey[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 (*OrderedByKey[K, V]) Values ¶
func (m *OrderedByKey[K, V]) Values() iter.Seq[V]
Values returns a sequence that yields all values in the map in order.
type Proto ¶
Proto is a map Protocol Buffers messages of type K to values of type V.
K must be a pointer type that implements proto.Message.
Key equality is determined based on the serialized form of the message, and so is subject to the caveats described by https://protobuf.dev/programming-guides/encoding/#implications.
At time of writing, the Go implementation provides deterministic output for the same input within the same binary/process, which is sufficient for the purposes of this type.
func NewProtoFromSeq ¶ added in v0.16.0
NewProtoFromSeq returns a Proto containing the key/value pairs yielded by the given sequence.
func (*Proto[K, V]) All ¶
All returns a sequence that yields all key/value pairs in the map in no particular order.
func (*Proto[K, V]) Get ¶
func (m *Proto[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 (*Proto[K, V]) Keys ¶
Keys returns a sequence that yields all keys in the map in no particular order.
func (*Proto[K, V]) Merge ¶
Merge returns a new map containing all key/value pairs from s and x.
If a key is present in both maps, the value from x is used.
func (*Proto[K, V]) Project ¶
Project constructs a new map by applying the given transform function to each key/value pair in the map. If the transform function returns false, the key is omitted from the resulting map.
func (*Proto[K, V]) Remove ¶
func (m *Proto[K, V]) Remove(keys ...K)
Remove removes the given keys from the map.
func (*Proto[K, V]) Select ¶
Select returns a new map containing all key/value pairs from m for which the given predicate returns true.
func (*Proto[K, V]) Set ¶
func (m *Proto[K, V]) Set(k K, v V)
Set sets the value associated with the given key.