Dictionary

package
v0.0.0-...-029f470 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 6, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package Dictionary provides a data structure that holds key-value pairs.

Index

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 Any

type Any = Map[variant.Any, variant.Any]
var Nil Any

type Interface

type Interface interface {
	Any() Any
}

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]) Any

func (m Map[K, V]) Any() Any

Any returns a dictionary with variant keys and values.

func (Map[K, V]) Erase

func (m Map[K, V]) Erase(key K) bool

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]) Has

func (m Map[K, V]) Has(key K) bool

Has returns true if the dictionary contains an entry with the given key.

func (Map[K, V]) HasAll

func (m Map[K, V]) HasAll(keys ...K) bool

HasAll returns true if the dictionary contains all the keys.

func (Map[K, V]) Hash

func (m Map[K, V]) Hash() uint32

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]) IsEmpty

func (m Map[K, V]) IsEmpty() bool

IsEmpty returns true if the dictionary is empty.

func (Map[K, V]) IsReadOnly

func (m Map[K, V]) IsReadOnly() bool

IsReadOnly returns true if the dictionary is read-only.

func (*Map[K, V]) Iter

func (m *Map[K, V]) Iter() iter.Seq2[K, V]

Iter returns an iterator for the dictionary.

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

func (m Map[K, V]) Len() int

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

func (m *Map[K, V]) Merge(dictionary Map[K, V])

Merge adds entries from dictionary to this dictionary. Duplicate keys are not copied over.

func (Map[K, V]) RecursivelyEqualTo

func (m Map[K, V]) RecursivelyEqualTo(other Map[K, V]) bool

RecursivelyEqualTo returns true if the two dictionaries contain the same keys and values, inner Dictionary and Array keys and values are compared recursively.

func (*Map[K, V]) SetAny

func (dict *Map[K, V]) SetAny(a Any)

func (*Map[K, V]) SetIndex

func (m *Map[K, V]) SetIndex(index K, value V)

SetIndex sets the value at the given index in the dictionary.

func (Map[K, V]) Values

func (m Map[K, V]) Values() []V

Values returns the list of values in this dictionary.

type Pointer

type Pointer interface {
	SetAny(Any)
}

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
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL