Documentation
¶
Index ¶
- type MapNode
- type OrderedMap
- func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Delete(key K) bool
- func (m *OrderedMap[K, V]) Get(key K) (V, bool)
- func (m *OrderedMap[K, V]) Iter() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *OrderedMap[K, V]) Set(key K, value V) bool
- func (m *OrderedMap[K, V]) ToArray() []V
- func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MapNode ¶
type MapNode[K comparable, V any] struct { K K V V }
MapNode represents a key-value pair in the OrderedMap.
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is a map that preserves the order of key-value pairs. It combines a map for fast lookups and a linked list for order preservation.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
NewOrderedMap creates and initializes a new OrderedMap.
func (*OrderedMap[K, V]) Copy ¶
func (m *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
Copy creates a deep copy of the OrderedMap.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) bool
Delete removes a key-value pair from the map. Returns true if the key was found and removed, false otherwise.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (V, bool)
Get retrieves a value from the map by key. Returns the value and a boolean indicating whether the key was found.
func (*OrderedMap[K, V]) Iter ¶
func (m *OrderedMap[K, V]) Iter() iter.Seq2[K, V]
Iter returns an iterator that yields key-value pairs in insertion order. The iterator directly uses the underlying linked list for iteration.
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]) MarshalJSON ¶
func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface. It serializes an OrderedMap into a JSON object, preserving the order of keys.
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V) bool
Set adds or updates a key-value pair in the map. Returns true if the key is new, false if it already existed.
func (*OrderedMap[K, V]) ToArray ¶
func (m *OrderedMap[K, V]) ToArray() []V
ToArray returns all values in the map as a slice, preserving the order.
func (*OrderedMap[K, V]) UnmarshalJSON ¶
func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface. It deserializes a JSON object into an OrderedMap, preserving the order of keys.