Documentation
¶
Index ¶
- Constants
- func CombineHash(seed, hash uint64) uint64
- func CombineHashes(hashes ...uint64) uint64
- func DeepEqual[T any](a, b T) bool
- func Equal[K comparable](k1, k2 K) bool
- func NewHasher[T comparable]() func(T) uint64
- type Map
- func (m *Map[K, V]) Clear()
- func (m *Map[K, V]) Get(key K) (V, bool)
- func (m *Map[K, V]) Iterator() *MapIterator[K, V]
- func (m *Map[K, V]) Len() int
- func (m *Map[K, V]) Put(key K, val V)
- func (m *Map[K, V]) Remove(key K) (MapElement[K, V], bool)
- func (m *Map[K, V]) Upsert(key K, update func(elem *MapElement[K, V], exists bool))
- type MapElement
- type MapIterator
Constants ¶
const (
HashSeed uint64 = 14695981039346656037 // Seed value for the initial hash
)
Variables ¶
This section is empty.
Functions ¶
func CombineHash ¶
CombineHash Combine two uint64 hashes into a single hash
func CombineHashes ¶
CombineHashes Combine a list of uint64 hashes into a single hash
func NewHasher ¶
func NewHasher[T comparable]() func(T) uint64
Hasher Returns a hash function for `comparable`
Types ¶
type Map ¶
type Map[K, V any] struct { // contains filtered or unexported fields }
Map is a generic hash map implementation that allows any type for keys. Map instance should be instantiated using the NewMap function.
func NewMap ¶
func NewMap[K any, V any](equal func(k1, k2 K) bool, hash func(k K) uint64, bucketSizeOpt ...int) *Map[K, V]
NewMap returns a new instance of Map[K, V] with the given equality and hash functions. The optional bucketSizeOpt parameter specifies the size of each bucket in the map. If not provided, a default bucket size (64k) is used. Special care should be taken when choosing a bucket size as it can have a significant impact on performance. For good performance, the bucket size should be close to the expected number of elements in the map.
func (*Map[K, V]) Iterator ¶
func (m *Map[K, V]) Iterator() *MapIterator[K, V]
Iterator returns a new iterator over the map.
func (*Map[K, V]) Put ¶
func (m *Map[K, V]) Put(key K, val V)
Put inserts the given key-value pair into the map.
func (*Map[K, V]) Remove ¶
func (m *Map[K, V]) Remove(key K) (MapElement[K, V], bool)
Remove removes the given key from the map and returns it.
func (*Map[K, V]) Upsert ¶
func (m *Map[K, V]) Upsert(key K, update func(elem *MapElement[K, V], exists bool))
Upsert inserts or modifies the given entry into the map. The update function is called with the current value or the new one.
type MapElement ¶
MapElement is a generic key-value pair used in the Map[K, V] implementation.
type MapIterator ¶
MapIterator is an iterator over a map.
func (*MapIterator[K, V]) Cur ¶
func (it *MapIterator[K, V]) Cur() *MapElement[K, V]
Cur returns the current element
func (*MapIterator[K, V]) Next ¶
func (it *MapIterator[K, V]) Next() bool
Next advances the iterator and returns true if there is another element
func (*MapIterator[K, V]) Remove ¶
func (it *MapIterator[K, V]) Remove() MapElement[K, V]
Remove removes the current element from the map and returns it. After calling Remove, Next must be called before calling Cur again.
func (*MapIterator[K, V]) Reset ¶
func (it *MapIterator[K, V]) Reset()
Reset resets the iterator to the beginning of the map.