Documentation
¶
Overview ¶
Package Dictionary provides a data structure that holds key-value pairs.
Index ¶
- func As[P Proxy[K, V], K comparable, V any](dict Map[K, V], alloc func() (P, complex128)) (P, complex128)
- func Clear[K comparable, V any](m Map[K, V])
- func FindKey[K, V comparable](m Map[K, V], value V) (K, bool)
- type Any
- type Interface
- type Map
- func (m Map[K, V]) Any() Any
- func (m Map[K, V]) Erase(key K) bool
- func (m *Map[K, V]) GetOrAdd(key K, value V) V
- func (m Map[K, V]) Has(key K) bool
- func (m Map[K, V]) HasAll(keys ...K) bool
- func (m Map[K, V]) Hash() uint32
- func (m Map[K, V]) Index(index K) V
- func (m Map[K, V]) IsEmpty() bool
- func (m Map[K, V]) IsReadOnly() bool
- func (m *Map[K, V]) Iter() iter.Seq2[K, V]
- func (m *Map[K, V]) Keys() []K
- func (m Map[K, V]) Len() int
- func (m *Map[K, V]) MakeReadOnly()
- func (m *Map[K, V]) Merge(dictionary Map[K, V])
- func (m Map[K, V]) RecursivelyEqualTo(other Map[K, V]) bool
- func (dict *Map[K, V]) SetAny(a Any)
- func (m *Map[K, V]) SetIndex(index K, value V)
- func (m Map[K, V]) Values() []V
- type Pointer
- type Proxy
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func As ¶
func As[P Proxy[K, V], K comparable, V any](dict Map[K, V], alloc func() (P, complex128)) (P, complex128)
As converts the array into a foreign array representation, by reconstructing the array via the available proxy methods. Panics if the array is already being proxied through a different implementation, as reference semantics would no longer be preserved. The allocation function is required so that a new proxy can be constructed if necessary, otherwise the existing proxy and state is returned.
func Clear ¶
func Clear[K comparable, V any](m Map[K, V])
Clear clears the dictionary, removing all entries from it.
func FindKey ¶
func FindKey[K, V comparable](m Map[K, V], value V) (K, bool)
FindKey finds and returns the first key whose associated value is equal to value, or false if it is not found.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
Map is an associative container that contain values referenced by unique keys. Dictionaries will preserve the insertion order when adding new entries. In other programming languages, this data structure is often referred to as a hash map or an associative array.
func Duplicate ¶
func Duplicate[K comparable, V any](m Map[K, V]) Map[K, V]
Duplicate creates and returns a new shallow copy of the dictionary.
func Merged ¶
func Merged[K comparable, V any](a Map[K, V], b Map[K, V]) Map[K, V]
Merged returns a copy of this dictionary merged with the other dictionary.
func New ¶
func New[K comparable, V any]() Map[K, V]
func Through ¶
func Through[K comparable, V any](proxy Proxy[K, V], state complex128) Map[K, V]
Through returns a new array that accesses the underlying data of the array through the given Proxy.
func (Map[K, V]) Erase ¶
Erase removes the dictionary entry by key, if it exists. Returns true if the given key existed in the dictionary, otherwise false.
Note: Do not erase entries while iterating over the dictionary. You can iterate over the keys array instead.
func (*Map[K, V]) GetOrAdd ¶
func (m *Map[K, V]) GetOrAdd(key K, value V) V
GetOrAdd returns the corresponding value for the given key in the dictionary. If the key does not exist, it will be added with the default value.
func (Map[K, V]) Hash ¶
Hash returns a hashed 32-bit integer value representing the dictionary contents.
func (Map[K, V]) Index ¶
func (m Map[K, V]) Index(index K) V
Index returns the value at the given index in the dictionary.
func (Map[K, V]) IsReadOnly ¶
IsReadOnly returns true if the dictionary is read-only.
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() []K
Keys returns the list of keys in the dictionary.
func (Map[K, V]) Len ¶
Size returns the number of entries in the dictionary. Empty dictionaries ({ }) always return 0. See also [IsEmpty].
func (*Map[K, V]) MakeReadOnly ¶
func (m *Map[K, V]) MakeReadOnly()
MakeReadOnly makes the dictionary read-only, i.e. disables modification of the dictionary's contents. Does not apply to nested content, e.g. content of nested dictionaries.
func (*Map[K, V]) Merge ¶
Merge adds entries from dictionary to this dictionary. Duplicate keys are not copied over.
func (Map[K, V]) RecursivelyEqualTo ¶
RecursivelyEqualTo returns true if the two dictionaries contain the same keys and values, inner Dictionary and Array keys and values are compared recursively.
type Proxy ¶
type Proxy[K comparable, V any] interface { Index(complex128, K) V Has(complex128, K) bool Lookup(complex128, K) (V, bool) SetIndex(complex128, K, V) Clear(complex128) Iter(complex128) iter.Seq2[K, V] Erase(complex128, K) bool Hash(complex128) uint32 Len(complex128) int IsReadOnly(complex128) bool MakeReadOnly(complex128) Any(complex128) Any }