Documentation
¶
Overview ¶
Package sequencedmap provides a map implementation that maintains the order of keys as they are added.
Index ¶
- func Len[K comparable, V any](m *Map[K, V]) int
- type Element
- type Map
- func (m *Map[K, V]) Add(key K, value V)
- func (m *Map[K, V]) AddAny(key, value any)
- func (m *Map[K, V]) All() iter.Seq2[K, V]
- func (m *Map[K, V]) AllOrdered(order OrderType) iter.Seq2[K, V]
- func (m *Map[K, V]) AllUntyped() iter.Seq2[any, any]
- func (m *Map[K, V]) At(index int) *Element[K, V]
- func (m *Map[K, V]) Delete(key K)
- func (m *Map[K, V]) DeleteAny(key any)
- func (m *Map[K, V]) First() *Element[K, V]
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) GetAny(key any) (any, bool)
- func (m *Map[K, V]) GetKeyType() reflect.Type
- func (m *Map[K, V]) GetOrZero(key K) V
- func (m *Map[K, V]) GetUntyped(key any) (any, bool)
- func (m *Map[K, V]) GetValueType() reflect.Type
- func (m *Map[K, V]) Has(key K) bool
- func (m *Map[K, V]) Init()
- func (m *Map[K, V]) IsEqual(other *Map[K, V]) bool
- func (m *Map[K, V]) IsEqualFunc(other *Map[K, V], equalFunc func(V, V) bool) bool
- func (m *Map[K, V]) IsInitialized() bool
- func (m *Map[K, V]) Keys() iter.Seq[K]
- func (m *Map[K, V]) KeysAny() iter.Seq[any]
- func (m *Map[K, V]) Last() *Element[K, V]
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) MarshalJSON() ([]byte, error)
- func (m *Map[K, V]) MarshalYAML() (interface{}, error)
- func (m *Map[K, V]) NavigateWithKey(key string) (any, error)
- func (m *Map[K, V]) Set(key K, value V)
- func (m *Map[K, V]) SetAny(key, value any)
- func (m *Map[K, V]) SetUntyped(key, value any) error
- func (m *Map[K, V]) UnmarshalYAML(value *yaml.Node) error
- func (m *Map[K, V]) Values() iter.Seq[V]
- type OrderType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Element ¶
type Element[K comparable, V any] struct { Key K Value V }
Element is a key-value pair that is stored in a sequenced map.
func NewElem ¶
func NewElem[K comparable, V any](key K, value V) *Element[K, V]
NewElem creates a new element with the specified key and value.
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is a map implementation that maintains the order of keys as they are added.
func From ¶ added in v1.0.0
func From[K comparable, V any](seq iter.Seq2[K, V]) *Map[K, V]
From creates a new map from the given sequence.
func New ¶
func New[K comparable, V any](elements ...*Element[K, V]) *Map[K, V]
New creates a new map with the specified elements.
func NewWithCapacity ¶
func NewWithCapacity[K comparable, V any](capacity int, elements ...*Element[K, V]) *Map[K, V]
NewWithCapacity creates a new map with the specified capacity and elements.
func (*Map[K, V]) Add ¶ added in v1.0.0
func (m *Map[K, V]) Add(key K, value V)
Add adds the specified key-value pair to the map. If the key already exists, it is moved to the end of the list.
func (*Map[K, V]) All ¶
All returns an iterator that iterates over all elements in the map, in the order they were added. The iterator is safe for concurrent mutations - it creates a snapshot at the start of iteration, so elements added or removed during iteration will not affect the current iteration.
func (*Map[K, V]) AllOrdered ¶ added in v1.0.0
AllOrdered returns an iterator that iterates over all elements in the map in the specified order. The iterator is safe for concurrent mutations - it creates a snapshot at the start of iteration, so elements added or removed during iteration will not affect the current iteration.
func (*Map[K, V]) AllUntyped ¶
AllUntyped returns an iterator that iterates over all elements in the map with untyped key and value. This allows for using the map in generic code. The iterator is safe for concurrent mutations - it creates a snapshot at the start of iteration.
func (*Map[K, V]) Delete ¶
func (m *Map[K, V]) Delete(key K)
Delete removes the element with the specified key from the map.
func (*Map[K, V]) Get ¶
Get returns the value for the specified key and a boolean indicating whether the key was found.
func (*Map[K, V]) GetKeyType ¶
GetKeyType returns the type of the keys in the map.
func (*Map[K, V]) GetOrZero ¶
func (m *Map[K, V]) GetOrZero(key K) V
GetOrZero returns the value for the specified key or the zero value if the key is not found.
func (*Map[K, V]) GetUntyped ¶
GetUntyped returns the untyped value for the specified key with untyped key and a boolean indicating whether the key was found. This allows for using the map in generic code. If they key is not of the correct type, the zero value is returned.
func (*Map[K, V]) GetValueType ¶
GetValueType returns the type of the values in the map.
func (*Map[K, V]) Has ¶
Has returns a boolean indicating whether the map contains the specified key.
func (*Map[K, V]) Init ¶
func (m *Map[K, V]) Init()
Init initializes the underlying resources of the map.
func (*Map[K, V]) IsEqual ¶ added in v1.0.0
IsEqual compares two Map instances for equality. It compares both the keys and values, and requires them to be in the same order. Treats both empty and nil maps as equal.
func (*Map[K, V]) IsEqualFunc ¶ added in v1.0.0
IsEqualFunc compares two Map instances for equality using a custom comparison function. This is useful when you need custom comparison logic for the values. Treats both empty and nil maps as equal.
func (*Map[K, V]) IsInitialized ¶ added in v1.0.0
IsInitialized returns true if the map has been initialized.
func (*Map[K, V]) Keys ¶
Keys returns an iterator that iterates over all keys in the map, in the order they were added. The iterator is safe for concurrent mutations - it creates a snapshot at the start of iteration.
func (*Map[K, V]) KeysAny ¶ added in v0.2.2
KeysAny Keys with any type The iterator is safe for concurrent mutations - it creates a snapshot at the start of iteration.
func (*Map[K, V]) MarshalJSON ¶
MarshalJSON returns the JSON representation of the map.
func (*Map[K, V]) MarshalYAML ¶ added in v1.0.1
MarshalYAML implements the yaml.Marshaler interface for the Map type. It marshals the sequenced map to YAML, preserving the order of keys.
func (*Map[K, V]) NavigateWithKey ¶
NavigateWithKey returns the value for the specified key with the key as a string. This is an implementation of the jsonpointer.KeyNavigable interface.
func (*Map[K, V]) Set ¶
func (m *Map[K, V]) Set(key K, value V)
Set sets the value for the specified key. If the key does not exist, it is added to the end of the list.
func (*Map[K, V]) SetUntyped ¶
SetUntyped sets the value for the specified key with untyped key and value. This allows for using the map in generic code. An error is returned if the key or value is not of the correct type.
func (*Map[K, V]) UnmarshalYAML ¶ added in v1.0.1
UnmarshalYAML implements the yaml.Unmarshaler interface for the Map type. It unmarshals YAML data into the sequenced map, preserving the order of keys.
type OrderType ¶ added in v1.0.0
type OrderType int
OrderType represents the different ways to order iteration through the map
const ( // OrderAdded iterates in the order items were added (default behavior) OrderAdded OrderType = iota // OrderAddedReverse iterates in reverse order of when items were added OrderAddedReverse // OrderKeyAsc iterates with keys in alphabetical ascending order OrderKeyAsc // OrderKeyDesc iterates with keys in alphabetical descending order OrderKeyDesc )