Documentation
¶
Overview ¶
Package omap provides a generic ordered map implementation that maintains insertion order of keys.
OrderedMap is parameterized as OrderedMap[K comparable, V any] and is used internally by the configuration tree to preserve the order of configuration keys.
Key Features ¶
- Maintains insertion order — iterating keys, values, or items always returns them in the order they were first inserted.
- Standard map operations: OrderedMap.Set, OrderedMap.Get, OrderedMap.Has, OrderedMap.Delete, OrderedMap.Len, OrderedMap.Clear.
- Go 1.23 iterators: OrderedMap.Keys (iter.Seq[K]), OrderedMap.Values (iter.Seq[V]), OrderedMap.Items (iter.Seq2[K, V]).
- NewWithCapacity for preallocated capacity when the expected size is known in advance.
Index ¶
- type OrderedMap
- func (m *OrderedMap[K, V]) Clear()
- func (m *OrderedMap[K, V]) Delete(key K) bool
- func (m *OrderedMap[K, V]) Get(key K) (V, bool)
- func (m *OrderedMap[K, V]) Has(key K) bool
- func (m *OrderedMap[K, V]) Items() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) Set(key K, value V)
- 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 OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap maintains key-value pairs with insertion order preservation.
func NewWithCapacity ¶
func NewWithCapacity[K comparable, V any](capacity int) *OrderedMap[K, V]
NewWithCapacity creates an empty OrderedMap with preallocated capacity.
func (*OrderedMap[K, V]) Clear ¶
func (m *OrderedMap[K, V]) Clear()
Clear removes all key-value pairs from the map.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) bool
Delete removes the key-value pair from the map. It returns true if the key was present and removed.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (V, bool)
Get returns the value associated with the key, and a boolean indicating whether the key exists.
func (*OrderedMap[K, V]) Has ¶
func (m *OrderedMap[K, V]) Has(key K) bool
Has returns true if the key exists in the map.
func (*OrderedMap[K, V]) Items ¶
func (m *OrderedMap[K, V]) Items() iter.Seq2[K, V]
Items returns an iterator over key-value pairs in insertion order.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
Keys returns an iterator over keys in insertion order.
func (*OrderedMap[K, V]) Len ¶
func (m *OrderedMap[K, V]) Len() int
Len returns the number of key-value pairs in the map.
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V)
Set sets the value for the given key. If the key is new, it is appended to the end of the order. If the key already exists, its value is updated and the order remains unchanged.
func (*OrderedMap[K, V]) Values ¶
func (m *OrderedMap[K, V]) Values() iter.Seq[V]
Values returns an iterator over values in insertion order.