maps

package
v0.16.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 5, 2024 License: MIT Imports: 7 Imported by: 0

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

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

func (m *Map[K, V]) All() iter.Seq2[K, V]

All returns a sequence that yields all key/value pairs in the map in no particular order.

func (*Map[K, V]) Clear

func (m *Map[K, V]) Clear()

Clear removes all keys from the map.

func (*Map[K, V]) Clone

func (m *Map[K, V]) Clone() *Map[K, V]

Clone returns a shallow copy of the map.

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]) Has

func (m *Map[K, V]) Has(keys ...K) bool

Has returns true if all of the given keys are in the map.

func (*Map[K, V]) Keys

func (m *Map[K, V]) Keys() iter.Seq[K]

Keys returns a sequence that yields all keys in the map in no particular order.

func (*Map[K, V]) Len

func (m *Map[K, V]) Len() int

Len returns the number of elements in the map.

func (*Map[K, V]) Merge

func (m *Map[K, V]) Merge(x *Map[K, V]) *Map[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 (*Map[K, V]) Project

func (m *Map[K, V]) Project(transform func(K, V) (K, V, bool)) *Map[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 (*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

func (m *Map[K, V]) Select(pred func(K, V) bool) *Map[K, V]

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.

func (*Map[K, V]) TryGet

func (m *Map[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 (*Map[K, V]) Values

func (m *Map[K, V]) Values() iter.Seq[V]

Values returns a sequence that yields all values in the map in no particular order.

type Ordered

type Ordered[K cmp.Ordered, V any] struct {
	// contains filtered or unexported fields
}

Ordered is an ordered map of keys of type K to values of type V.

func NewOrdered

func NewOrdered[K cmp.Ordered, V any](pairs ...Pair[K, V]) *Ordered[K, V]

NewOrdered returns an Ordered containing the given key/value pairs.

func NewOrderedFromSeq added in v0.16.0

func NewOrderedFromSeq[K cmp.Ordered, V any](seq iter.Seq2[K, V]) *Ordered[K, V]

NewOrderedFromSeq returns an Ordered containing the key/value pairs yielded by the given sequence.

func (*Ordered[K, V]) All

func (m *Ordered[K, V]) All() iter.Seq2[K, V]

All returns a sequence that yields all key/value pairs in the map in order.

func (*Ordered[K, V]) Clear

func (m *Ordered[K, V]) Clear()

Clear removes all keys from the map.

func (*Ordered[K, V]) Clone

func (m *Ordered[K, V]) Clone() *Ordered[K, V]

Clone returns a shallow copy of the map.

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]) Has

func (m *Ordered[K, V]) Has(keys ...K) bool

Has returns true if all of the given keys are in the map.

func (*Ordered[K, V]) Keys

func (m *Ordered[K, V]) Keys() iter.Seq[K]

Keys returns a sequence that yields all keys in the map in order.

func (*Ordered[K, V]) Len

func (m *Ordered[K, V]) Len() int

Len returns the number of elements in the map.

func (*Ordered[K, V]) Merge

func (m *Ordered[K, V]) Merge(x *Ordered[K, V]) *Ordered[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 (*Ordered[K, V]) Project

func (m *Ordered[K, V]) Project(transform func(K, V) (K, V, bool)) *Ordered[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 (*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

func (m *Ordered[K, V]) Reverse() iter.Seq2[K, V]

Reverse returns a sequence that yields all key/value pairs in the map in reverse order.

func (*Ordered[K, V]) ReverseKeys

func (m *Ordered[K, V]) ReverseKeys() iter.Seq[K]

ReverseKeys returns a sequence that yields all keys in the map in reverse order.

func (*Ordered[K, V]) ReverseValues

func (m *Ordered[K, V]) ReverseValues() iter.Seq[V]

ReverseValues returns a sequence that yields all values in the map in reverse order.

func (*Ordered[K, V]) Select

func (m *Ordered[K, V]) Select(pred func(K, V) bool) *Ordered[K, V]

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.

func (*Ordered[K, V]) TryGet

func (m *Ordered[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 (*Ordered[K, V]) Values

func (m *Ordered[K, V]) Values() iter.Seq[V]

Values returns a sequence that yields all values in the map in order.

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 Pair

type Pair[K, V any] struct {
	Key   K
	Value V
}

Pair is a key/value Pair.

type Proto

type Proto[K proto.Message, V any] struct {
	// contains filtered or unexported fields
}

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 NewProto

func NewProto[K proto.Message, V any](pairs ...Pair[K, V]) *Proto[K, V]

NewProto returns a Proto containing the given key/value pairs.

func NewProtoFromSeq added in v0.16.0

func NewProtoFromSeq[K proto.Message, V any](seq iter.Seq2[K, V]) *Proto[K, V]

NewProtoFromSeq returns a Proto containing the key/value pairs yielded by the given sequence.

func (*Proto[K, V]) All

func (m *Proto[K, V]) All() iter.Seq2[K, V]

All returns a sequence that yields all key/value pairs in the map in no particular order.

func (*Proto[K, V]) Clear

func (m *Proto[K, V]) Clear()

Clear removes all keys from the map.

func (*Proto[K, V]) Clone

func (m *Proto[K, V]) Clone() *Proto[K, V]

Clone returns a shallow copy of the map.

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]) Has

func (m *Proto[K, V]) Has(keys ...K) bool

Has returns true if all of the given keys are in the map.

func (*Proto[K, V]) Keys

func (m *Proto[K, V]) Keys() iter.Seq[K]

Keys returns a sequence that yields all keys in the map in no particular order.

func (*Proto[K, V]) Len

func (m *Proto[K, V]) Len() int

Len returns the number of elements in the map.

func (*Proto[K, V]) Merge

func (m *Proto[K, V]) Merge(x *Proto[K, V]) *Proto[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 (*Proto[K, V]) Project

func (m *Proto[K, V]) Project(transform func(K, V) (K, V, bool)) *Proto[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 (*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

func (m *Proto[K, V]) Select(pred func(K, V) bool) *Proto[K, V]

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.

func (*Proto[K, V]) TryGet

func (m *Proto[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 (*Proto[K, V]) Values

func (m *Proto[K, V]) Values() iter.Seq[V]

Values returns a sequence that yields all values in the map in no particular order.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
JackTT - Gopher 🇻🇳