Documentation
¶
Overview ¶
Package orderedmap provides an insertion-ordered map.
NOT safe for concurrent use. Callers must synchronize access externally.
Index ¶
- type OrderedMap
- func (o *OrderedMap[K, V]) Add(key K, val V)
- func (o *OrderedMap[K, V]) Clear()
- func (o *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
- func (o *OrderedMap[K, V]) Exists(key K) bool
- func (o *OrderedMap[K, V]) Get(key K) (V, bool)
- func (o *OrderedMap[K, V]) GetAll() ([]K, []V)
- func (o *OrderedMap[K, V]) GetMap() map[K]V
- func (o *OrderedMap[K, V]) Iterator(size int) chan V
- func (o *OrderedMap[K, V]) Keys() []K
- func (o *OrderedMap[K, V]) Remove(key K)
- func (o *OrderedMap[K, V]) SetAll(values []V)
- func (o *OrderedMap[K, V]) SetKeys(keys []K, def V)
- func (o *OrderedMap[K, V]) Size() int
- func (o *OrderedMap[K, V]) Values() []V
- type SafeOrderedMap
- func (s *SafeOrderedMap[K, V]) Add(key K, val V)
- func (s *SafeOrderedMap[K, V]) Clear()
- func (s *SafeOrderedMap[K, V]) Copy() *SafeOrderedMap[K, V]
- func (s *SafeOrderedMap[K, V]) Exists(key K) bool
- func (s *SafeOrderedMap[K, V]) Get(key K) (V, bool)
- func (s *SafeOrderedMap[K, V]) GetAll() ([]K, []V)
- func (s *SafeOrderedMap[K, V]) GetMap() map[K]V
- func (s *SafeOrderedMap[K, V]) Iterator(size int) chan V
- func (s *SafeOrderedMap[K, V]) Keys() []K
- func (s *SafeOrderedMap[K, V]) Remove(key K)
- func (s *SafeOrderedMap[K, V]) SetAll(values []V)
- func (s *SafeOrderedMap[K, V]) SetKeys(keys []K, def V)
- func (s *SafeOrderedMap[K, V]) Size() int
- func (s *SafeOrderedMap[K, V]) Values() []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 is a map that preserves insertion order of keys.
func (*OrderedMap[K, V]) Add ¶
func (o *OrderedMap[K, V]) Add(key K, val V)
Add inserts or updates the value for the given key, preserving insertion order.
func (*OrderedMap[K, V]) Clear ¶
func (o *OrderedMap[K, V]) Clear()
Clear removes all entries from the map.
func (*OrderedMap[K, V]) Copy ¶
func (o *OrderedMap[K, V]) Copy() *OrderedMap[K, V]
Copy returns a shallow copy of the ordered map.
func (*OrderedMap[K, V]) Exists ¶
func (o *OrderedMap[K, V]) Exists(key K) bool
Exists reports whether the given key is present in the map.
func (*OrderedMap[K, V]) Get ¶
func (o *OrderedMap[K, V]) Get(key K) (V, bool)
Get returns the value for the given key and whether it exists.
func (*OrderedMap[K, V]) GetAll ¶
func (o *OrderedMap[K, V]) GetAll() ([]K, []V)
GetAll returns copies of all keys and values in insertion order.
func (*OrderedMap[K, V]) GetMap ¶
func (o *OrderedMap[K, V]) GetMap() map[K]V
GetMap returns a plain map copy of all key-value pairs.
func (*OrderedMap[K, V]) Iterator ¶
func (o *OrderedMap[K, V]) Iterator(size int) chan V
Iterator returns a buffered channel that yields all values in insertion order.
func (*OrderedMap[K, V]) Keys ¶
func (o *OrderedMap[K, V]) Keys() []K
Keys returns a copy of all keys in insertion order.
func (*OrderedMap[K, V]) Remove ¶
func (o *OrderedMap[K, V]) Remove(key K)
Remove deletes the entry for the given key.
func (*OrderedMap[K, V]) SetAll ¶
func (o *OrderedMap[K, V]) SetAll(values []V)
SetAll replaces all values in key order; the slice must be at least as long as the number of keys.
func (*OrderedMap[K, V]) SetKeys ¶
func (o *OrderedMap[K, V]) SetKeys(keys []K, def V)
SetKeys adds multiple keys with the same default value.
func (*OrderedMap[K, V]) Size ¶
func (o *OrderedMap[K, V]) Size() int
Size returns the number of entries in the map.
func (*OrderedMap[K, V]) Values ¶
func (o *OrderedMap[K, V]) Values() []V
Values returns all values in insertion order.
type SafeOrderedMap ¶
type SafeOrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
SafeOrderedMap is a thread-safe wrapper around OrderedMap. All methods are protected by a read-write mutex.
func (*SafeOrderedMap[K, V]) Add ¶
func (s *SafeOrderedMap[K, V]) Add(key K, val V)
Add delegates to the underlying OrderedMap under a write lock.
func (*SafeOrderedMap[K, V]) Clear ¶
func (s *SafeOrderedMap[K, V]) Clear()
Clear delegates to the underlying OrderedMap under a write lock.
func (*SafeOrderedMap[K, V]) Copy ¶
func (s *SafeOrderedMap[K, V]) Copy() *SafeOrderedMap[K, V]
Copy delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) Exists ¶
func (s *SafeOrderedMap[K, V]) Exists(key K) bool
Exists delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) Get ¶
func (s *SafeOrderedMap[K, V]) Get(key K) (V, bool)
Get delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) GetAll ¶
func (s *SafeOrderedMap[K, V]) GetAll() ([]K, []V)
GetAll delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) GetMap ¶
func (s *SafeOrderedMap[K, V]) GetMap() map[K]V
GetMap delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) Iterator ¶
func (s *SafeOrderedMap[K, V]) Iterator(size int) chan V
Iterator delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) Keys ¶
func (s *SafeOrderedMap[K, V]) Keys() []K
Keys returns a copy of all keys in insertion order.
func (*SafeOrderedMap[K, V]) Remove ¶
func (s *SafeOrderedMap[K, V]) Remove(key K)
Remove delegates to the underlying OrderedMap under a write lock.
func (*SafeOrderedMap[K, V]) SetAll ¶
func (s *SafeOrderedMap[K, V]) SetAll(values []V)
SetAll delegates to the underlying OrderedMap under a write lock.
func (*SafeOrderedMap[K, V]) SetKeys ¶
func (s *SafeOrderedMap[K, V]) SetKeys(keys []K, def V)
SetKeys delegates to the underlying OrderedMap under a write lock.
func (*SafeOrderedMap[K, V]) Size ¶
func (s *SafeOrderedMap[K, V]) Size() int
Size delegates to the underlying OrderedMap under a read lock.
func (*SafeOrderedMap[K, V]) Values ¶
func (s *SafeOrderedMap[K, V]) Values() []V
Values returns all values in insertion order.