Documentation
¶
Overview ¶
Package hashmap implements a map backed by a hash table.
Elements are unordered in the map.
Structure is not thread safe.
Index ¶
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Clone() container.Map[K, V]
- func (m *Map[K, V]) Delete(key K) (value V, found bool)
- func (m *Map[K, V]) Entries() (keys []K, values []V)
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) Has(key K) bool
- func (m *Map[K, V]) IsEmpty() 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]) MarshalJSON() ([]byte, error)
- func (m *Map[K, V]) Put(key K, value V)
- func (m *Map[K, V]) String() string
- func (m *Map[K, V]) ToSlice() []V
- func (m *Map[K, V]) UnmarshalJSON(data []byte) error
- func (m *Map[K, V]) UnsortedEntries() (keys []K, values []V)
- func (m *Map[K, V]) UnsortedKeys() []K
- func (m *Map[K, V]) UnsortedValues() []V
- func (m *Map[K, V]) Values() []V
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Map ¶
type Map[K comparable, V any] struct { // contains filtered or unexported fields }
func NewWith ¶ added in v0.4.0
func NewWith[K comparable, V any](cmp cmp.Comparator[K], size int) *Map[K, V]
NewWith instantiates a hash map with the specified size and key comparator. If cmp is nil, SortedKeys will panic or produce undefined behavior.
func (*Map[K, V]) Clear ¶
func (m *Map[K, V]) Clear()
Clear removes all key-value pairs from the map.
func (*Map[K, V]) Clone ¶ added in v0.4.0
Clone returns a new Map containing all key-value pairs from the current map, with the same comparator.
func (*Map[K, V]) Delete ¶ added in v0.4.0
Delete removes the key-value pair associated with the specified key. Returns the value and true if the key was found and removed, false if the key was not present.
func (*Map[K, V]) Entries ¶ added in v0.4.0
func (m *Map[K, V]) Entries() (keys []K, values []V)
SortedEntries returns two slices containing all keys and values in the map, sorted by keys using m.cmp.
func (*Map[K, V]) Get ¶
Get retrieves the value associated with the specified key. Returns the value and true if the key was found, or the zero value of V and false if not.
func (*Map[K, V]) Has ¶ added in v0.4.0
Has returns true if the specified key is present in the map, false otherwise.
func (*Map[K, V]) IsEmpty ¶ added in v0.4.0
IsEmpty returns true if the map contains no key-value pairs.
func (*Map[K, V]) Iter ¶ added in v0.4.0
Iter returns an iterator over key-value pairs from m. The iteration order is not specified and is not guaranteed to be the same from one call to the next.
func (*Map[K, V]) Keys ¶
func (m *Map[K, V]) Keys() []K
Keys returns a slice containing all keys in the map, sorted using the comparator.
func (*Map[K, V]) MarshalJSON ¶
MarshalJSON outputs the JSON representation of the map.
func (*Map[K, V]) Put ¶
func (m *Map[K, V]) Put(key K, value V)
Put associates the specified value with the given key in the map. If the key already exists, its value is updated with the new value.
func (*Map[K, V]) ToSlice ¶ added in v0.4.0
func (m *Map[K, V]) ToSlice() []V
ToSlice returns a slice containing all values in the map (in random order).
func (*Map[K, V]) UnmarshalJSON ¶
UnmarshalJSON populates the map from the input JSON representation. The comparator is preserved.
func (*Map[K, V]) UnsortedEntries ¶ added in v0.8.0
func (m *Map[K, V]) UnsortedEntries() (keys []K, values []V)
UnsortedEntries returns two slices containing all keys and values in the map (in random order).
func (*Map[K, V]) UnsortedKeys ¶ added in v0.8.0
func (m *Map[K, V]) UnsortedKeys() []K
UnsortedKeys returns a slice containing all keys in the map (in random order).
func (*Map[K, V]) UnsortedValues ¶ added in v0.8.0
func (m *Map[K, V]) UnsortedValues() []V
UnsortedValues returns a slice containing all values in the map (in random order).