Documentation ¶
Index ¶
- func Equal[K, V comparable](m1, m2 *OrderedMap[K, V]) bool
- type AccessOrderedMap
- type BidiMap
- func (bm *BidiMap[K, V]) AddBidiMap(m *BidiMap[K, V])
- func (bm *BidiMap[K, V]) AddMap(m map[K]V)
- func (bm *BidiMap[K, V]) Clear()
- func (bm *BidiMap[K, V]) Clone() *BidiMap[K, V]
- func (bm BidiMap[K, V]) Equals(m *BidiMap[K, V]) bool
- func (bm BidiMap[K, V]) Get(key K) (value V, found bool)
- func (bm BidiMap[K, V]) GetKey(value V) (key K, found bool)
- func (bm BidiMap[K, V]) Keys() []K
- func (bm BidiMap[K, V]) Len() int
- func (m *BidiMap[K, V]) MarshalJSON() ([]byte, error)
- func (bm *BidiMap[K, V]) Put(key K, value V)
- func (bm BidiMap[K, V]) Range(f func(key K, value V) bool)
- func (bm *BidiMap[K, V]) Remove(key K)
- func (bm *BidiMap[K, V]) RemoveValue(value V)
- func (m *BidiMap[K, V]) UnmarshalJSON(data []byte) error
- func (bm BidiMap[K, V]) Values() []V
- type Entry
- type OrderedMap
- func (m *OrderedMap[K, V]) AddEntries(entries ...*Entry[K, V])
- func (m *OrderedMap[K, V]) AddMap(am map[K]V)
- func (m *OrderedMap[K, V]) AddOrderedMap(am OrderedMap[K, V])
- func (m *OrderedMap[K, V]) Clear()
- func (m *OrderedMap[K, V]) Clone() *OrderedMap[K, V]
- func (m *OrderedMap[K, V]) Delete(key K) (val V, existed bool)
- func (m *OrderedMap[K, V]) ForEach(f func(key K, value V) bool)
- func (m *OrderedMap[K, V]) Get(key K) (val V, existed bool)
- func (m *OrderedMap[K, V]) Keys() []K
- func (m *OrderedMap[K, V]) Len() int
- func (m *OrderedMap[K, V]) Load(key K) (V, bool)
- func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
- func (m *OrderedMap[K, V]) Newest() *Entry[K, V]
- func (m *OrderedMap[K, V]) Oldest() *Entry[K, V]
- func (m *OrderedMap[K, V]) Range(f func(key K, value V) bool)
- func (m *OrderedMap[K, V]) Set(key K, value V) (val V, existed bool)
- func (m *OrderedMap[K, V]) Store(key K, value V) (V, bool)
- func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
- func (m *OrderedMap[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Equal ¶
func Equal[K, V comparable](m1, m2 *OrderedMap[K, V]) bool
Equal returns true if the given maps are equal to the map in order.
Types ¶
type AccessOrderedMap ¶
type AccessOrderedMap[K comparable, V any] struct { *OrderedMap[K, V] }
AccessOrderedMap is a map with access order.
func NewAccessOrderedMap ¶
func NewAccessOrderedMap[K comparable, V any](capability int) *AccessOrderedMap[K, V]
NewOrderedMap creates an empty OrderedMap. The parameter `capability` is the initial size of the map.
func (*AccessOrderedMap[K, V]) Get ¶
func (m *AccessOrderedMap[K, V]) Get(key K) (val V, existed bool)
Get returns the value of the given key.
func (*AccessOrderedMap[K, V]) Load ¶
func (m *AccessOrderedMap[K, V]) Load(key K) (V, bool)
Load returns the value of the given key, alias for Get.
type BidiMap ¶
type BidiMap[K, V comparable] struct { // contains filtered or unexported fields }
BidiMap is a bidirectional map, which efines a map that allows bidirectional lookup between key and values. This map represents a mapping where a key may lookup a value and a value may lookup a key with equal ease. Its key and value types must be comparable, and it enforces the restriction that there is a 1:1 relation between keys and values, meaning that multiple keys cannot map to the same value.
func NewBidiMap ¶
func NewBidiMap[K, V comparable](capacity int) *BidiMap[K, V]
NewBidiMap returns a new bidirectional map with the given capacity.
func (*BidiMap[K, V]) AddBidiMap ¶
AddBidiMap adds all the key/value pairs from the given map.
func (*BidiMap[K, V]) AddMap ¶
func (bm *BidiMap[K, V]) AddMap(m map[K]V)
AddMap adds all the key/value pairs from the given map. You must guarantee that the map has a 1:1 relation between keys and values.
func (*BidiMap[K, V]) Clear ¶
func (bm *BidiMap[K, V]) Clear()
Clear removes all the keys and values.
func (BidiMap[K, V]) Get ¶
Get returns the value associated with the given key, and whether it existed or not.
func (BidiMap[K, V]) GetKey ¶
GetKey returns the key associated with the given value, and whether it existed or not.
func (BidiMap[K, V]) Keys ¶
func (bm BidiMap[K, V]) Keys() []K
Keys returns a slice of all the keys.
func (*BidiMap[K, V]) MarshalJSON ¶
MarshalJSON marshals the map into JSON.
func (*BidiMap[K, V]) Put ¶
func (bm *BidiMap[K, V]) Put(key K, value V)
Put associates the given key with the given value. If the key or value already existed, it will be overwritten.
func (BidiMap[K, V]) Range ¶
Range calls the given function for each key/value pair. If the function returns false, it stops the iteration.
func (*BidiMap[K, V]) Remove ¶
func (bm *BidiMap[K, V]) Remove(key K)
Remove removes the given key and its associated value. If the key does not exist, it does nothing.
func (*BidiMap[K, V]) RemoveValue ¶
func (bm *BidiMap[K, V]) RemoveValue(value V)
RemoveValue removes the given value and its associated key. If the value does not exist, it does nothing.
func (*BidiMap[K, V]) UnmarshalJSON ¶
UnmarshalJSON unmarshals the map from JSON.
type Entry ¶
type Entry[K comparable, V any] struct { Key K Value V // contains filtered or unexported fields }
Entry is a key-value pair in OrderedMap.
type OrderedMap ¶
type OrderedMap[K comparable, V any] struct { // contains filtered or unexported fields }
OrderedMap is a map with insert order.
func NewOrderedMap ¶
func NewOrderedMap[K comparable, V any](capability int) *OrderedMap[K, V]
NewOrderedMap creates an empty OrderedMap. The parameter `capability` is the initial size of the map.
func (*OrderedMap[K, V]) AddEntries ¶
func (m *OrderedMap[K, V]) AddEntries(entries ...*Entry[K, V])
AddEntries adds entries to the map.
func (*OrderedMap[K, V]) AddMap ¶
func (m *OrderedMap[K, V]) AddMap(am map[K]V)
AddMap adds entries of the given map to the map.
func (*OrderedMap[K, V]) AddOrderedMap ¶
func (m *OrderedMap[K, V]) AddOrderedMap(am OrderedMap[K, V])
AddOrderedMap adds entries of the given OrderedMap to the map.
func (*OrderedMap[K, V]) Clone ¶
func (m *OrderedMap[K, V]) Clone() *OrderedMap[K, V]
Clone returns a shallow copy of the map.
func (*OrderedMap[K, V]) Delete ¶
func (m *OrderedMap[K, V]) Delete(key K) (val V, existed bool)
Len returns the length of the map.
func (*OrderedMap[K, V]) ForEach ¶
func (m *OrderedMap[K, V]) ForEach(f func(key K, value V) bool)
ForEach calls f for each value in the map as random order like builtin map.
func (*OrderedMap[K, V]) Get ¶
func (m *OrderedMap[K, V]) Get(key K) (val V, existed bool)
Get returns the value of the given key.
func (*OrderedMap[K, V]) Keys ¶
func (m *OrderedMap[K, V]) Keys() []K
Keys returns all keys of the map as insert order.
func (*OrderedMap[K, V]) Len ¶
func (m *OrderedMap[K, V]) Len() int
Len returns the length of the map.
func (*OrderedMap[K, V]) Load ¶
func (m *OrderedMap[K, V]) Load(key K) (V, bool)
Load returns the value of the given key, alias for Get.
func (*OrderedMap[K, V]) MarshalJSON ¶
func (m *OrderedMap[K, V]) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.Marshaler interface.
func (*OrderedMap[K, V]) Newest ¶
func (m *OrderedMap[K, V]) Newest() *Entry[K, V]
Newest returns the newest entry of the map.
func (*OrderedMap[K, V]) Oldest ¶
func (m *OrderedMap[K, V]) Oldest() *Entry[K, V]
Oldest returns the oldest entry of the map.
func (*OrderedMap[K, V]) Range ¶
func (m *OrderedMap[K, V]) Range(f func(key K, value V) bool)
Range calls f sequentially for each key and value in the map as insert order .
func (*OrderedMap[K, V]) Set ¶
func (m *OrderedMap[K, V]) Set(key K, value V) (val V, existed bool)
Set sets the value of the given key. It returns the old value if the key existed otherwise it returns the passed new value. The second return value is true if the key existed.
func (*OrderedMap[K, V]) Store ¶
func (m *OrderedMap[K, V]) Store(key K, value V) (V, bool)
Store sets the value of the given key, alias for Set.
func (*OrderedMap[K, V]) UnmarshalJSON ¶
func (m *OrderedMap[K, V]) UnmarshalJSON(data []byte) error
UnmarshalJSON implements the json.Unmarshaler interface.
func (*OrderedMap[K, V]) Values ¶
func (m *OrderedMap[K, V]) Values() []V
Values returns all values of the map as insert order.