...

Package concurrent

import "internal/concurrent"
Overview
Index

Overview ▾

type HashTrieMap

HashTrieMap is an implementation of a concurrent hash-trie. The implementation is designed around frequent loads, but offers decent performance for stores and deletes as well, especially if the map is larger. It's primary use-case is the unique package, but can be used elsewhere as well.

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

func NewHashTrieMap

func NewHashTrieMap[K, V comparable]() *HashTrieMap[K, V]

NewHashTrieMap creates a new HashTrieMap for the provided key and value.

func (*HashTrieMap[K, V]) All

func (ht *HashTrieMap[K, V]) All() func(yield func(K, V) bool)

All returns an iter.Seq2 that produces all key-value pairs in the map. The enumeration does not represent any consistent snapshot of the map, but is guaranteed to visit each unique key-value pair only once. It is safe to operate on the tree during iteration. No particular enumeration order is guaranteed.

func (*HashTrieMap[K, V]) CompareAndDelete

func (ht *HashTrieMap[K, V]) CompareAndDelete(key K, old V) (deleted bool)

CompareAndDelete deletes the entry for key if its value is equal to old.

If there is no current value for key in the map, CompareAndDelete returns false (even if the old value is the nil interface value).

func (*HashTrieMap[K, V]) Load

func (ht *HashTrieMap[K, V]) Load(key K) (value V, ok bool)

Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.

func (*HashTrieMap[K, V]) LoadOrStore

func (ht *HashTrieMap[K, V]) LoadOrStore(key K, value V) (result V, loaded bool)

LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.