Documentation
¶
Index ¶
- type Element
- type OrderedMap
- 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]) Iterator() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Keys() (keys []K)
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) ReplaceKey(originalKey, newKey K) bool
- func (m *OrderedMap[K, V]) ReverseIterator() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Set(key K, value V) bool
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 ¶ added in v2.6.0
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 ¶ added in v2.5.0
func NewOrderedMapWithElements[K comparable, V any](els ...*Element[K, V]) *OrderedMap[K, V]
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 v2.7.0
func (m *OrderedMap[K, V]) Has(key K) bool
Has checks if a key exists in the map.
func (*OrderedMap[K, V]) Iterator ¶ added in v2.5.0
func (m *OrderedMap[K, V]) Iterator() iter.Seq2[K, V]
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() (keys []K)
Keys returns all of the keys in the order they were inserted. If a key was replaced it will retain the same position. To ensure most recently set keys are always at the end you must always Delete before Set.
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 ¶ added in v2.3.0
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]) ReverseIterator ¶ added in v2.5.0
func (m *OrderedMap[K, V]) ReverseIterator() iter.Seq2[K, V]
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).