dict

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HashDict added in v0.3.0

type HashDict[K comparable, V any] map[K]V

HashDict is a Golang builtin map wrapper.

func NewHashDict added in v0.3.0

func NewHashDict[K comparable, V any]() *HashDict[K, V]

NewHashDict creates a new HashDict.

func (*HashDict[K, V]) Clear added in v0.3.0

func (m *HashDict[K, V]) Clear()

Clear removes all key-value pairs in this dictionary.

func (*HashDict[K, V]) Clone added in v0.3.0

func (m *HashDict[K, V]) Clone() collection.Dict[K, V]

Clone returns a copy of this dictionary.

func (*HashDict[K, V]) ContainsKey added in v0.3.0

func (m *HashDict[K, V]) ContainsKey(k K) bool

ContainsKey returns true if this dictionary contains a key-value pair with the specified key.

func (*HashDict[K, V]) Equals added in v0.3.0

func (m *HashDict[K, V]) Equals(o any) bool

Equals compares this dictionary with the object pass from parameter.

func (*HashDict[K, V]) ForEach added in v0.3.0

func (m *HashDict[K, V]) ForEach(handler func(K, V) error) error

ForEach performs the given handler for each key-value pairs in the dictionary until all pairs have been processed or the handler returns an error.

func (*HashDict[K, V]) Get added in v0.3.0

func (m *HashDict[K, V]) Get(k K) (V, bool)

Get returns the value which associated to the specified key.

func (*HashDict[K, V]) GetDefault added in v0.3.0

func (m *HashDict[K, V]) GetDefault(k K, defaultVal V) V

GetDefault returns the value associated with the specified key, and returns the default value if this dictionary contains no pair with the key.

func (*HashDict[K, V]) IsEmpty added in v0.3.0

func (m *HashDict[K, V]) IsEmpty() bool

IsEmpty returns true if this dictionary is empty.

func (*HashDict[K, V]) Iter added in v0.3.0

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

Iter returns an iterator of all elements in this dictionary.

func (*HashDict[K, V]) Keys added in v0.3.0

func (m *HashDict[K, V]) Keys() []K

Keys returns a slice that contains all the keys in this dictionary.

func (*HashDict[K, V]) KeysIter added in v0.4.0

func (m *HashDict[K, V]) KeysIter() iter.Seq[K]

KeysIter returns an iterator of all keys in this dictionary.

func (*HashDict[K, V]) MarshalJSON added in v0.5.0

func (m *HashDict[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the HashDict as a JSON object (map).

func (*HashDict[K, V]) Put added in v0.3.0

func (m *HashDict[K, V]) Put(k K, v V) V

Put associate the specified value with the specified key in this dictionary.

func (*HashDict[K, V]) Remove added in v0.3.0

func (m *HashDict[K, V]) Remove(k K) V

Remove removes the key-value pair with the specified key.

func (*HashDict[K, V]) Replace added in v0.3.0

func (m *HashDict[K, V]) Replace(k K, v V) (V, bool)

Replace replaces the value for the specified key only if it is currently in this dictionary.

func (*HashDict[K, V]) Size added in v0.3.0

func (m *HashDict[K, V]) Size() int

Size returns the number of key-value pairs in this dictionary.

func (*HashDict[K, V]) String added in v0.5.0

func (m *HashDict[K, V]) String() string

String returns the string representation of this dictionary.

func (*HashDict[K, V]) UnmarshalJSON added in v0.5.0

func (m *HashDict[K, V]) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a JSON object into the HashDict.

func (*HashDict[K, V]) Values added in v0.3.0

func (m *HashDict[K, V]) Values() []V

Values returns a slice that contains all the values in this dictionary.

func (*HashDict[K, V]) ValuesIter added in v0.4.0

func (m *HashDict[K, V]) ValuesIter() iter.Seq[V]

ValuesIter returns an iterator of all values in this dictionary.

type LockDict added in v0.5.0

type LockDict[K comparable, V any] struct {
	// contains filtered or unexported fields
}

LockDict is a thread-safe dictionary using a read-write mutex.

func NewLockDict added in v0.5.0

func NewLockDict[K comparable, V any]() *LockDict[K, V]

NewLockDict creates a new LockDict.

func (*LockDict[K, V]) Clear added in v0.5.0

func (m *LockDict[K, V]) Clear()

Clear removes all key-value pairs in this dictionary.

func (*LockDict[K, V]) Clone added in v0.5.0

func (m *LockDict[K, V]) Clone() collection.Dict[K, V]

Clone returns a copy of this dictionary.

func (*LockDict[K, V]) ContainsKey added in v0.5.0

func (m *LockDict[K, V]) ContainsKey(k K) bool

ContainsKey returns true if this dictionary contains a key-value pair with the specified key.

func (*LockDict[K, V]) Equals added in v0.5.0

func (m *LockDict[K, V]) Equals(o any) bool

Equals compares this dictionary with the object pass from parameter.

func (*LockDict[K, V]) ForEach added in v0.5.0

func (m *LockDict[K, V]) ForEach(handler func(K, V) error) error

ForEach performs the given handler for each key-value pairs in the dictionary until all pairs have been processed or the handler returns an error.

func (*LockDict[K, V]) Get added in v0.5.0

func (m *LockDict[K, V]) Get(k K) (V, bool)

Get returns the value which associated to the specified key.

func (*LockDict[K, V]) GetDefault added in v0.5.0

func (m *LockDict[K, V]) GetDefault(k K, defaultVal V) V

GetDefault returns the value associated with the specified key, and returns the default value if this dictionary contains no pair with the key.

func (*LockDict[K, V]) IsEmpty added in v0.5.0

func (m *LockDict[K, V]) IsEmpty() bool

IsEmpty returns true if this dictionary is empty.

func (*LockDict[K, V]) Iter added in v0.5.0

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

Iter returns an iterator of all elements in this dictionary.

func (*LockDict[K, V]) Keys added in v0.5.0

func (m *LockDict[K, V]) Keys() []K

Keys returns a slice that contains all the keys in this dictionary.

func (*LockDict[K, V]) KeysIter added in v0.5.0

func (m *LockDict[K, V]) KeysIter() iter.Seq[K]

KeysIter returns an iterator of all keys in this dictionary.

func (*LockDict[K, V]) MarshalJSON added in v0.5.0

func (m *LockDict[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the HashDict as a JSON object (map).

func (*LockDict[K, V]) Put added in v0.5.0

func (m *LockDict[K, V]) Put(k K, v V) V

Put associate the specified value with the specified key in this dictionary.

func (*LockDict[K, V]) Remove added in v0.5.0

func (m *LockDict[K, V]) Remove(k K) V

Remove removes the key-value pair with the specified key.

func (*LockDict[K, V]) Replace added in v0.5.0

func (m *LockDict[K, V]) Replace(k K, v V) (V, bool)

Replace replaces the value for the specified key only if it is currently in this dictionary.

func (*LockDict[K, V]) Size added in v0.5.0

func (m *LockDict[K, V]) Size() int

Size returns the number of key-value pairs in this dictionary.

func (*LockDict[K, V]) String added in v0.5.0

func (m *LockDict[K, V]) String() string

String returns the string representation of this dictionary.

func (*LockDict[K, V]) UnmarshalJSON added in v0.5.0

func (m *LockDict[K, V]) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a JSON object into the HashDict.

func (*LockDict[K, V]) Values added in v0.5.0

func (m *LockDict[K, V]) Values() []V

Values returns a slice that contains all the values in this dictionary.

func (*LockDict[K, V]) ValuesIter added in v0.5.0

func (m *LockDict[K, V]) ValuesIter() iter.Seq[V]

ValuesIter returns an iterator of all values in this dictionary.

type SyncDict added in v0.3.0

type SyncDict[K comparable, V any] struct {
	// contains filtered or unexported fields
}

SyncDict is a thread-safe map implementation based on sync.Map's algorithm.

func NewSyncDict added in v0.3.0

func NewSyncDict[K comparable, V any]() *SyncDict[K, V]

NewSyncDict creates a new SyncDict.

func (*SyncDict[K, V]) Clear added in v0.3.0

func (d *SyncDict[K, V]) Clear()

// Clear removes all key-value pairs in this dictionary.

func (*SyncDict[K, V]) Clone added in v0.3.0

func (d *SyncDict[K, V]) Clone() collection.Dict[K, V]

Clone returns a copy of this dictionary.

func (*SyncDict[K, V]) ContainsKey added in v0.3.0

func (d *SyncDict[K, V]) ContainsKey(key K) bool

ContainsKey returns true if this dictionary contains a key-value pair with the specified key.

func (*SyncDict[K, V]) Equals added in v0.3.0

func (d *SyncDict[K, V]) Equals(o any) bool

Equals compares this dictionary with the object pass from parameter.

func (*SyncDict[K, V]) ForEach added in v0.3.0

func (d *SyncDict[K, V]) ForEach(handler func(K, V) error) error

ForEach performs the given handler for each key-value pairs in the dictionary until all pairs have been processed or the handler returns an error.

func (*SyncDict[K, V]) Get added in v0.3.0

func (d *SyncDict[K, V]) Get(key K) (V, bool)

Get returns the value which associated to the specified key.

func (*SyncDict[K, V]) GetDefault added in v0.3.0

func (d *SyncDict[K, V]) GetDefault(key K, defaultVal V) V

GetDefault returns the value associated with the specified key, and returns the default value if this dictionary contains no pair with the key.

func (*SyncDict[K, V]) IsEmpty added in v0.3.0

func (d *SyncDict[K, V]) IsEmpty() bool

IsEmpty returns true if this dictionary is empty.

func (*SyncDict[K, V]) Iter added in v0.3.0

func (d *SyncDict[K, V]) Iter() iter.Seq2[K, V]

Iter returns an iterator of all elements in this dictionary.

func (*SyncDict[K, V]) Keys added in v0.3.0

func (d *SyncDict[K, V]) Keys() []K

Keys returns a slice that contains all the keys in this dictionary.

func (*SyncDict[K, V]) KeysIter added in v0.4.0

func (d *SyncDict[K, V]) KeysIter() iter.Seq[K]

KeysIter returns an iterator of all keys in this dictionary.

func (*SyncDict[K, V]) MarshalJSON added in v0.5.0

func (d *SyncDict[K, V]) MarshalJSON() ([]byte, error)

MarshalJSON marshals the SyncDict as a JSON object (map).

func (*SyncDict[K, V]) Put added in v0.3.0

func (d *SyncDict[K, V]) Put(key K, val V) V

Put associate the specified value with the specified key in this dictionary.

func (*SyncDict[K, V]) Remove added in v0.3.0

func (d *SyncDict[K, V]) Remove(key K) V

Remove removes the key-value pair with the specified key.

func (*SyncDict[K, V]) Replace added in v0.3.0

func (d *SyncDict[K, V]) Replace(key K, val V) (V, bool)

Replace replaces the value for the specified key only if it is currently in this dictionary.

func (*SyncDict[K, V]) Size added in v0.3.0

func (d *SyncDict[K, V]) Size() int

Size returns the number of key-value pairs in this dictionary.

func (*SyncDict[K, V]) String added in v0.5.0

func (d *SyncDict[K, V]) String() string

String returns the string representation of this dictionary.

func (*SyncDict[K, V]) UnmarshalJSON added in v0.5.0

func (d *SyncDict[K, V]) UnmarshalJSON(b []byte) error

UnmarshalJSON unmarshals a JSON object into the SyncDict.

func (*SyncDict[K, V]) Values added in v0.3.0

func (d *SyncDict[K, V]) Values() []V

Values returns a slice that contains all the values in this dictionary.

func (*SyncDict[K, V]) ValuesIter added in v0.4.0

func (d *SyncDict[K, V]) ValuesIter() iter.Seq[V]

ValuesIter returns an iterator of all values in this dictionary.

Jump to

Keyboard shortcuts

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