xxmap

package
v0.0.4-d-oss Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

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

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ObjectsMap

type ObjectsMap[K, V any] []sync.Map

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

type ObjectsSet[T any] []sync.Map

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

type StringMap[T any] []sync.Map

StringMap is a concurrent map from string keys to values of type T, internally sharded across shards sync.Map instances.

func NewStringMap

func NewStringMap[T any]() StringMap[T]

NewStringMap returns an empty StringMap.

func (StringMap[T]) Get

func (t StringMap[T]) Get(key string) T

Get returns the value stored under key, or the zero value of T if absent.

func (StringMap[T]) GoRange

func (t StringMap[T]) GoRange(f func(key string, value T) bool)

GoRange is like Range but iterates the shards concurrently.

func (StringMap[T]) Len

func (t StringMap[T]) Len() int

Len returns the number of entries in t.

func (StringMap[T]) Put

func (t StringMap[T]) Put(key string, value T)

Put stores value under key, replacing any previous value.

func (StringMap[T]) PutIfMissing

func (t StringMap[T]) PutIfMissing(key string, value T) bool

PutIfMissing stores value under key only if no value is present, and reports whether the value was inserted.

func (StringMap[T]) Range

func (t StringMap[T]) Range(f func(key string, value T) bool)

Range calls f sequentially for every (key, value) pair. Iteration stops when f returns false.

func (StringMap[T]) Remove

func (t StringMap[T]) Remove(key string)

Remove deletes any value stored under key.

type StringsSet

type StringsSet []sync.Map

StringsSet is a concurrent set of strings.

func NewStringsSet

func NewStringsSet() StringsSet

NewStringsSet returns an empty StringsSet.

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) Len

func (t StringsSet) Len() int

Len returns the number of strings 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL