Documentation
¶
Index ¶
- type OrderedMap
- func (om *OrderedMap[K, V]) Get(key K) (V, bool)
- func (om *OrderedMap[K, V]) Keys() []K
- func (om *OrderedMap[K, V]) Len() int
- func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (om *OrderedMap[K, V]) Range(fn func(key K, value V) bool)
- func (om *OrderedMap[K, V]) Set(key K, value V)
- func (om *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
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 preserves insertion order when marshaling/unmarshaling JSON. This ensures that JSON object keys maintain their original order rather than being alphabetically sorted during marshal operations.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any]() *OrderedMap[K, V]
NewOrderedMap creates a new OrderedMap.
func (*OrderedMap[K, V]) Get ¶
func (om *OrderedMap[K, V]) Get(key K) (V, bool)
Get retrieves a value by key.
func (*OrderedMap[K, V]) Keys ¶
func (om *OrderedMap[K, V]) Keys() []K
Keys returns all keys in insertion order.
func (*OrderedMap[K, V]) Len ¶
func (om *OrderedMap[K, V]) Len() int
Len returns the number of key-value pairs.
func (*OrderedMap[K, V]) MarshalJSON ¶
func (om *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON implements json.Marshaler, writing keys in insertion order.
func (*OrderedMap[K, V]) Range ¶
func (om *OrderedMap[K, V]) Range(fn func(key K, value V) bool)
Range iterates over the map in insertion order.
func (*OrderedMap[K, V]) Set ¶
func (om *OrderedMap[K, V]) Set(key K, value V)
Set stores a value with the given key, preserving insertion order.
func (*OrderedMap[K, V]) UnmarshalJSON ¶
func (om *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler, preserving key order.
Click to show internal directories.
Click to hide internal directories.