Documentation ¶
Index ¶
- type Element
- type OrderedMap
- func (m *OrderedMap[K, V]) AllFromBack() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) AllFromFront() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Back() *Element[K, V]
- func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Delete(key K) (didDelete bool)
- func (m *OrderedMap[K, V]) Front() *Element[K, V]
- func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool)
- func (m *OrderedMap[K, V]) GetElement(key K) *Element[K, V]
- func (m *OrderedMap[K, V]) GetOrDefault(key K, defaultValue V) V
- func (m *OrderedMap[K, V]) Has(key K) bool
- func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) ReplaceKey(originalKey, newKey K) bool
- func (m *OrderedMap[K, V]) Set(key K, value V) bool
- func (m *OrderedMap[K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Element ¶
type Element[K comparable, V any] struct { // The key that corresponds to this element in the ordered map. Key K // The value stored with this element. Value V // contains filtered or unexported fields }
Element is an element of a null terminated (non circular) intrusive doubly linked list that contains the key of the correspondent element in the ordered map too.
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
func NewOrderedMapWithCapacity ¶
func NewOrderedMapWithCapacity[K comparable, V any](capacity int) *OrderedMap[K, V]
NewOrderedMapWithCapacity creates a map with enough pre-allocated space to hold the specified number of elements.
func NewOrderedMapWithElements ¶
func NewOrderedMapWithElements[K comparable, V any](els ...*Element[K, V]) *OrderedMap[K, V]
func (*OrderedMap[K, V]) AllFromBack ¶
func (m *OrderedMap[K, V]) AllFromBack() iter.Seq2[K, V]
AllFromBack returns an iterator that yields all elements in the map starting at the back (most recent Set element).
func (*OrderedMap[K, V]) AllFromFront ¶
func (m *OrderedMap[K, V]) AllFromFront() iter.Seq2[K, V]
AllFromFront returns an iterator that yields all elements in the map starting at the front (oldest Set element).
func (*OrderedMap[K, V]) Back ¶
func (m *OrderedMap[K, V]) Back() *Element[K, V]
Back will return the element that is the last (most recent Set element). If there are no elements this will return nil.
func (*OrderedMap[K, V]) Copy ¶
func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
Copy returns a new OrderedMap with the same elements. Using Copy while there are concurrent writes may mangle the result.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) (didDelete bool)
Delete will remove a key from the map. It will return true if the key was removed (the key did exist).
func (*OrderedMap[K, V]) Front ¶
func (m *OrderedMap[K, V]) Front() *Element[K, V]
Front will return the element that is the first (oldest Set element). If there are no elements this will return nil.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (value V, ok bool)
Get returns the value for a key. If the key does not exist, the second return parameter will be false and the value will be nil.
func (*OrderedMap[K, V]) GetElement ¶
func (m *OrderedMap[K, V]) GetElement(key K) *Element[K, V]
GetElement returns the element for a key. If the key does not exist, the pointer will be nil.
func (*OrderedMap[K, V]) GetOrDefault ¶
func (m *OrderedMap[K, V]) GetOrDefault(key K, defaultValue V) V
GetOrDefault returns the value for a key. If the key does not exist, returns the default value instead.
func (*OrderedMap[K, V]) Has ¶ added in v3.1.0
func (m *OrderedMap[K, V]) Has(key K) bool
Has checks if a key exists in the map.
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 starting at the front (oldest Set element). To create a slice containing all the map keys, use the slices.Collect function on the returned iterator.
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]) ReplaceKey ¶
func (m *OrderedMap[K, V]) ReplaceKey(originalKey, newKey K) bool
ReplaceKey replaces an existing key with a new key while preserving order of the value. This function will return true if the operation was successful, or false if 'originalKey' is not found OR 'newKey' already exists (which would be an overwrite).
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V) bool
Set will set (or replace) a value for a key. If the key was new, then true will be returned. The returned value will be false if the value was replaced (even if the value was the same).
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 starting at the front (oldest Set element). To create a slice containing all the map values, use the slices.Collect function on the returned iterator.