Documentation
¶
Overview ¶
Package hashmap wraps the Go built-in map and provides a more intuitive API. It is safe for concurrent use.
Index ¶
- type HashMap
- func (m *HashMap[K, V]) All() iter.Seq2[K, V]
- func (m *HashMap[K, V]) Clear()
- func (m *HashMap[K, V]) Contains(key K) bool
- func (m *HashMap[K, V]) Empty() bool
- func (m *HashMap[K, V]) Get(key K) (V, bool)
- func (m *HashMap[K, V]) Insert(key K, value V)
- func (m *HashMap[K, V]) Keys() iter.Seq[K]
- func (m *HashMap[K, V]) Len() int
- func (m *HashMap[K, V]) Remove(key K)
- func (m *HashMap[K, V]) Values() iter.Seq[V]
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HashMap ¶
type HashMap[K comparable, V any] struct { // contains filtered or unexported fields }
HashMap is a generic hash table (map).
func Collect ¶
func Collect[K comparable, V any](seq iter.Seq2[K, V]) *HashMap[K, V]
Collect collects key-value pairs from an iterator and returns a new map.
func (*HashMap[K, V]) All ¶
All returns an iterator over key-value pairs in the map. The iteration order is unspecified and not guaranteed to remain the same between calls.
The iterator must not modify the map to avoid deadlock.
func (*HashMap[K, V]) Clear ¶
func (m *HashMap[K, V]) Clear()
Clear removes all key-value pairs from the map.
func (*HashMap[K, V]) Get ¶
Get retrieves the value associated with the key. If the key does not exist, it returns the zero value of the value type and false.
func (*HashMap[K, V]) Insert ¶
func (m *HashMap[K, V]) Insert(key K, value V)
Insert inserts a key-value pair into the map.
If the map does not contain the key, it will be added.
If the map already contains the key, the value will be updated.
func (*HashMap[K, V]) Keys ¶
Keys returns an iterator over keys in the map. The iteration order is unspecified and not guaranteed to remain the same between calls.
The iterator must not modify the map to avoid deadlock.