Documentation
¶
Overview ¶
Package orderedmap implements an ordered map, that is; a map that remembers the order in which key, value pairs were inserted.
Index ¶
- type Map
- func (m *Map[K, V]) All() iter.Seq2[K, V]
- func (m *Map[K, V]) Contains(key K) bool
- func (m *Map[K, V]) Get(key K) (value V, ok bool)
- func (m *Map[K, V]) GetOrInsert(key K, value V) (val V, existed bool)
- func (m *Map[K, V]) Insert(key K, value V) (val V, existed bool)
- func (m *Map[K, V]) Keys() iter.Seq[K]
- func (m *Map[K, V]) Newest() (key K, value V, ok bool)
- func (m *Map[K, V]) Oldest() (key K, value V, ok bool)
- func (m *Map[K, V]) Remove(key K) (value V, existed bool)
- func (m *Map[K, V]) Size() int
- func (m *Map[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 ordered map.
func WithCapacity ¶ added in v0.15.0
func WithCapacity[K comparable, V any](capacity int) *Map[K, V]
WithCapacity creates and returns a new ordered Map with the given capacity.
This can be a useful performance improvement when the expected maximum size of the map is known ahead of time as it eliminates the need for reallocation.
func (*Map[K, V]) All ¶ added in v0.18.0
All returns an iterator over the entries in the map in the order in which they were inserted.
func (*Map[K, V]) Contains ¶ added in v0.8.0
Contains reports whether the map contains the given key.
func (*Map[K, V]) Get ¶
Get returns the value stored against the given key in the map and a boolean to indicate presence, like the standard Go map.
If the requested key wasn't in the map, the zero value for the item and false are returned. If the key was present, the item and true are returned.
func (*Map[K, V]) GetOrInsert ¶
GetOrInsert fetches a value by it's key if it is present in the map, and if not inserts the passed in value against that key instead.
The returned boolean reports whether the key already existed.
func (*Map[K, V]) Insert ¶
Insert inserts a new value into the map against the given key, returning the previous value and a boolean to indicate presence.
If the map did not have this key present before the call to Insert, it will return the value just inserted and false.
If the map did have this key, and this call to Insert is therefore an update of an existing value, then the old value and true are returned.
func (*Map[K, V]) Keys ¶
Keys returns an iterator over the keys in the map in the order in which they were inserted.
func (*Map[K, V]) Newest ¶
Newest returns the newest key, value pair in the map, i.e. the pair that was inserted last. Note that in place modifications do not update the order.
func (*Map[K, V]) Oldest ¶
Oldest returns the oldest key, value pair in the map, i.e. the pair that was inserted first. Note that in place modifications do not update the order.
func (*Map[K, V]) Remove ¶
Remove removes a key from the map, returning the stored value and a boolean to indicate whether it was in the map to begin with.
If the value was in the map, the removed value and true are returned, if not the zero value for the value type and false are returned.