Documentation
¶
Overview ¶
DO NOT EDIT THIS FILE GENERATED BY cmd/gencompareany/gencompareany.go
Index ¶
- func Equal[K cmp.Ordered, V any](m1, m2 *OrderedMap[K, V]) bool
- type OrderedMap
- func (m *OrderedMap[K, V]) All() iter.Seq2[K, V]
- func (m *OrderedMap[K, V]) Delete(key K) bool
- func (m *OrderedMap[K, V]) DeleteWithSlicesDeleteFunc(key K) bool
- func (m *OrderedMap[K, V]) Get(key K) (V, bool)
- func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
- 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]) Sort()
- func (m *OrderedMap[K, V]) UnmarshalJSON(b []byte) error
- func (m *OrderedMap[K, V]) Values() iter.Seq[V]
- type Pair
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type OrderedMap ¶
func New ¶
func New[K cmp.Ordered, V any]() *OrderedMap[K, V]
New returns an OrderedMap ready to use.
Example:
om := orderedmap.New[string, int]()
func NewFromKeysValues ¶
func NewFromKeysValues[K cmp.Ordered, V any](keys []K, values []V) *OrderedMap[K, V]
NewFromKeysValues returns an OrderedMap with keys[i]=>values[i] for all 0 <= i < len(keys). It's an error if len(keys) != len(values).
Parallel arrays technique.
func NewFromPairs ¶ added in v0.3.0
func NewFromPairs[K cmp.Ordered, V any](pairs []Pair[K, V]) *OrderedMap[K, V]
Example use:
m := orderedmap.NewFromPairs([]orderedmap.Pair[string, int]{
{"cat", 600},
{"badger", 500},
{"centipede", 400},
{"bog", 300},
{"foist", 200},
{"cake", 100},
})
func (*OrderedMap[K, V]) All ¶ added in v0.5.0
func (m *OrderedMap[K, V]) All() iter.Seq2[K, V]
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) bool
Delete deletes the key and its associated value. It returns a boolean indicating whether the key existed or not.
Same as for Set, my inclination was to not return a value, but elliotchance/orderedmap Delete does. So...
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]) DeleteWithSlicesDeleteFunc ¶ added in v0.5.0
func (m *OrderedMap[K, V]) DeleteWithSlicesDeleteFunc(key K) bool
Alternative Delete using slices package.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (V, bool)
Get returns the value associated with key and a boolean indicating whether or not the key exists.
Does this alias memory? No. This is tested by TestGet/DoesGetAliasMemory.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() iter.Seq[K]
func (*OrderedMap[K, V]) MarshalJSON ¶ added in v0.4.0
func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V) bool
Set sets key=>value. If key exists, its value is replaced and key retains its order in the list. If key doesn't exist, it's added at the end of the ordering.
My inclination was for this to not return a value, but elliotchance/orderedmap (where I took the tests from) Set *does* return a bool. So... I guess I will.
Here is their function comment:
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).
func (*OrderedMap[K, V]) Sort ¶ added in v0.5.0
func (m *OrderedMap[K, V]) Sort()
func (*OrderedMap[K, V]) UnmarshalJSON ¶ added in v0.4.0
func (m *OrderedMap[K, V]) UnmarshalJSON(b []byte) error
func (*OrderedMap[K, V]) Values ¶
func (m *OrderedMap[K, V]) Values() iter.Seq[V]