Documentation
¶
Overview ¶
Package xxmap provides a concurrent string-keyed map sharded by xxhash, trading a fixed amount of memory for reduced contention compared to a single sync.Map under highly parallel access.
Index ¶
- type ObjectsMap
- func (t ObjectsMap[K, V]) Get(key *K) (V, bool)
- func (t ObjectsMap[K, V]) GoRange(f func(key *K, value V) bool)
- func (t ObjectsMap[K, V]) Len() int
- func (t ObjectsMap[K, V]) Put(key *K, value V)
- func (t ObjectsMap[K, V]) PutIfMissing(key *K, value V) bool
- func (t ObjectsMap[K, V]) Range(f func(key *K, value V) bool)
- func (t ObjectsMap[K, V]) Remove(key *K)
- type ObjectsSet
- type StringMap
- func (t StringMap[T]) Get(key string) T
- func (t StringMap[T]) GoRange(f func(key string, value T) bool)
- func (t StringMap[T]) Len() int
- func (t StringMap[T]) Put(key string, value T)
- func (t StringMap[T]) PutIfMissing(key string, value T) bool
- func (t StringMap[T]) Range(f func(key string, value T) bool)
- func (t StringMap[T]) Remove(key string)
- type StringsSet
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ObjectsMap ¶
ObjectsMap is a concurrent map keyed by *K values, sharded by pointer address.
func NewObjectsMap ¶
func NewObjectsMap[K, V any]() ObjectsMap[K, V]
NewObjectsMap returns an empty ObjectsMap.
func (ObjectsMap[K, V]) Get ¶
func (t ObjectsMap[K, V]) Get(key *K) (V, bool)
Get returns the value stored under key and whether such an entry exists.
func (ObjectsMap[K, V]) GoRange ¶
func (t ObjectsMap[K, V]) GoRange(f func(key *K, value V) bool)
GoRange is like Range but iterates the shards concurrently.
func (ObjectsMap[K, V]) Len ¶
func (t ObjectsMap[K, V]) Len() int
Len returns the number of entries in t.
func (ObjectsMap[K, V]) Put ¶
func (t ObjectsMap[K, V]) Put(key *K, value V)
Put stores value under key, replacing any previous value.
func (ObjectsMap[K, V]) PutIfMissing ¶
func (t ObjectsMap[K, V]) PutIfMissing(key *K, value V) bool
PutIfMissing stores value under key only if no value is present, and reports whether the value was inserted.
func (ObjectsMap[K, V]) Range ¶
func (t ObjectsMap[K, V]) Range(f func(key *K, value V) bool)
Range calls f sequentially for every (key, value) pair. Iteration stops when f returns false.
func (ObjectsMap[K, V]) Remove ¶
func (t ObjectsMap[K, V]) Remove(key *K)
Remove deletes any value stored under key.
type ObjectsSet ¶
ObjectsSet is a concurrent set of *T values, sharded by pointer address. The element type is given as T (rather than *T) to work around Go's limitations on using pointer types in generic constraints.
func NewObjectsSet ¶
func NewObjectsSet[T any]() ObjectsSet[T]
NewObjectsSet returns an empty ObjectsSet.
func (ObjectsSet[T]) GoRange ¶
func (t ObjectsSet[T]) GoRange(f func(obj *T) bool)
GoRange is like Range but iterates the shards concurrently.
func (ObjectsSet[T]) Has ¶
func (t ObjectsSet[T]) Has(obj *T) bool
Has reports whether obj is in the set.
func (ObjectsSet[T]) Len ¶
func (t ObjectsSet[T]) Len() int
Len returns the number of objects in the set.
func (ObjectsSet[T]) Put ¶
func (t ObjectsSet[T]) Put(obj *T) bool
Put inserts obj into the set and reports whether it was newly added.
func (ObjectsSet[T]) Range ¶
func (t ObjectsSet[T]) Range(f func(obj *T) bool)
Range calls f sequentially for every object in the set. Iteration stops when f returns false.
type StringMap ¶
StringMap is a concurrent map from string keys to values of type T, internally sharded across shards sync.Map instances.
func NewStringMap ¶
NewStringMap returns an empty StringMap.
func (StringMap[T]) PutIfMissing ¶
PutIfMissing stores value under key only if no value is present, and reports whether the value was inserted.
type StringsSet ¶
StringsSet is a concurrent set of strings.
func (StringsSet) GoRange ¶
func (t StringsSet) GoRange(f func(key string) bool)
GoRange is like Range but iterates the shards concurrently.
func (StringsSet) Has ¶
func (t StringsSet) Has(key string) bool
Has reports whether key is in the set.
func (StringsSet) Put ¶
func (t StringsSet) Put(key string) bool
Put inserts key into the set and reports whether it was newly added.
func (StringsSet) Range ¶
func (t StringsSet) Range(f func(key string) bool)
Range calls f sequentially for every key in the set. Iteration stops when f returns false.