concurrent

package
v1.18.4 Latest Latest
Warning

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

Go to latest
Published: Jan 22, 2024 License: Apache-2.0 Imports: 5 Imported by: 6

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConcurrentHashMap added in v1.12.3

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

ConcurrentHashMap A "thread" safe map of type string:Anything. To avoid lock bottlenecks this map is dived to several (__SHARD_COUNT) map shards.

func NewHashMap added in v1.12.4

func NewHashMap[K comparable, V any]() ConcurrentHashMap[K, V]

func NewStringMap added in v1.12.4

func NewStringMap[V any]() ConcurrentHashMap[string, V]

NewStringMap Creates a new concurrent map.

func NewStringer added in v1.12.3

func NewStringer[K Stringer, V any]() ConcurrentHashMap[K, V]

NewStringer Creates a new concurrent map.

func NewWithCustomShardingFunction added in v1.12.3

func NewWithCustomShardingFunction[K comparable, V any](sharding func(key K) uint32) ConcurrentHashMap[K, V]

NewWithCustomShardingFunction Creates a new concurrent map.

func (*ConcurrentHashMap[K, V]) Clear added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Clear()

Clear removes all items from map.

func (*ConcurrentHashMap[K, V]) Count added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Count() int

Count returns the number of elements within the map.

func (*ConcurrentHashMap[K, V]) Get added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Get(key K) (V, bool)

Get retrieves an element from map under given key.

func (*ConcurrentHashMap[K, V]) GetShard added in v1.12.3

func (m *ConcurrentHashMap[K, V]) GetShard(key K) *ConcurrentMapShared[K, V]

GetShard returns shard under given key

func (*ConcurrentHashMap[K, V]) Has added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Has(key K) bool

Looks up an item under specified key

func (*ConcurrentHashMap[K, V]) IsEmpty added in v1.12.3

func (m *ConcurrentHashMap[K, V]) IsEmpty() bool

IsEmpty checks if map is empty.

func (*ConcurrentHashMap[K, V]) Items added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Items() map[K]V

Items returns all items as map[string]V

func (*ConcurrentHashMap[K, V]) Iter deprecated added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Iter() <-chan Tuple[K, V]

Iter returns an iterator which could be used in a for range loop.

Deprecated: using IterBuffered() will get a better performence

func (*ConcurrentHashMap[K, V]) IterBuffered added in v1.12.3

func (m *ConcurrentHashMap[K, V]) IterBuffered() <-chan Tuple[K, V]

IterBuffered returns a buffered iterator which could be used in a for range loop.

func (*ConcurrentHashMap[K, V]) IterCb added in v1.12.3

func (m *ConcurrentHashMap[K, V]) IterCb(fn IterCb[K, V])

Callback based iterator, cheapest way to read all elements in a map.

func (*ConcurrentHashMap[K, V]) Keys added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Keys() []K

Keys returns all keys as []string

func (*ConcurrentHashMap[K, V]) MSet added in v1.12.3

func (m *ConcurrentHashMap[K, V]) MSet(data map[K]V)

func (*ConcurrentHashMap[K, V]) MarshalJSON added in v1.12.3

func (m *ConcurrentHashMap[K, V]) MarshalJSON() ([]byte, error)

Reviles ConcurrentHashMap "private" variables to json marshal.

func (*ConcurrentHashMap[K, V]) Pop added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Pop(key K) (v V, exists bool)

Pop removes an element from the map and returns it

func (*ConcurrentHashMap[K, V]) Remove added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Remove(key K)

Remove removes an element from the map.

func (*ConcurrentHashMap[K, V]) RemoveCb added in v1.12.3

func (m *ConcurrentHashMap[K, V]) RemoveCb(key K, cb RemoveCb[K, V]) bool

RemoveCb locks the shard containing the key, retrieves its current value and calls the callback with those params If callback returns true and element exists, it will remove it from the map Returns the value returned by the callback (even if element was not present in the map)

func (*ConcurrentHashMap[K, V]) Set added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Set(key K, value V)

Sets the given value under the specified key.

func (*ConcurrentHashMap[K, V]) SetIfAbsent added in v1.12.3

func (m *ConcurrentHashMap[K, V]) SetIfAbsent(key K, value V) bool

Sets the given value under the specified key if no value was associated with it.

func (*ConcurrentHashMap[K, V]) UnmarshalJSON added in v1.12.3

func (m *ConcurrentHashMap[K, V]) UnmarshalJSON(b []byte) (err error)

UnmarshalJSON Reverse process of Marshal.

func (*ConcurrentHashMap[K, V]) Upsert added in v1.12.3

func (m *ConcurrentHashMap[K, V]) Upsert(key K, value V, cb UpsertCb[V]) (res V)

Insert or Update - updates existing element or inserts a new one using UpsertCb

type ConcurrentMapShared added in v1.12.3

type ConcurrentMapShared[K comparable, V any] struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

ConcurrentMapShared A "thread" safe string to anything map.

type IterCb added in v1.12.3

type IterCb[K comparable, V any] func(key K, v V)

Iterator callbacalled for every key,value found in maps. RLock is held for all calls for a given shard therefore callback sess consistent view of a shard, but not across the shards

type RemoveCb added in v1.12.3

type RemoveCb[K any, V any] func(key K, v V, exists bool) bool

RemoveCb is a callback executed in a map.RemoveCb() call, while Lock is held If returns true, the element will be removed from the map

type Stringer added in v1.12.3

type Stringer interface {
	fmt.Stringer
	comparable
}

type TreeMap

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

func NewTreeMap

func NewTreeMap[K cmp.Ordered, V any]() *TreeMap[K, V]

func (*TreeMap[K, V]) Clear added in v1.13.6

func (m *TreeMap[K, V]) Clear()

func (*TreeMap[K, V]) Each

func (m *TreeMap[K, V]) Each(f func(key K, value V))

func (*TreeMap[K, V]) Get

func (m *TreeMap[K, V]) Get(k K) (v V, found bool)

func (*TreeMap[K, V]) Put

func (m *TreeMap[K, V]) Put(k K, v V)

func (*TreeMap[K, V]) Size added in v1.13.6

func (m *TreeMap[K, V]) Size() int

type Tuple added in v1.12.3

type Tuple[K comparable, V any] struct {
	Key K
	Val V
}

Used by the Iter & IterBuffered functions to wrap two variables together over a channel,

type UpsertCb added in v1.12.3

type UpsertCb[V any] func(exist bool, valueInMap V, newValue V) V

Callback to return new element to be inserted into the map It is called while lock is held, therefore it MUST NOT try to access other keys in same map, as it can lead to deadlock since Go sync.RWLock is not reentrant

Jump to

Keyboard shortcuts

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