hiboot: hidevops.io/hiboot/pkg/utils/cmap Index | Files

package cmap

import "hidevops.io/hiboot/pkg/utils/cmap"

Package cmap provides concurrent map

Index

Package Files

concurrent_map.go

type ConcurrentMap Uses

type ConcurrentMap []*ConcurrentMapShared

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

func New Uses

func New() ConcurrentMap

New Creates a new concurrent map.

func (ConcurrentMap) Count Uses

func (m ConcurrentMap) Count() int

Count returns the number of elements within the map.

func (ConcurrentMap) Get Uses

func (m ConcurrentMap) Get(key string) (interface{}, bool)

Get Retrieves an element from map under given key.

func (ConcurrentMap) GetShard Uses

func (m ConcurrentMap) GetShard(key string) *ConcurrentMapShared

GetShard Returns shard under given key

func (ConcurrentMap) Has Uses

func (m ConcurrentMap) Has(key string) bool

Has Looks up an item under specified key

func (ConcurrentMap) IsEmpty Uses

func (m ConcurrentMap) IsEmpty() bool

IsEmpty Checks if map is empty.

func (ConcurrentMap) Items Uses

func (m ConcurrentMap) Items() map[string]interface{}

Items Returns all items as map[string]interface{}

func (ConcurrentMap) Iter Uses

func (m ConcurrentMap) Iter() <-chan Tuple

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

Deprecated: using IterBuffered() will get a better performance

func (ConcurrentMap) IterBuffered Uses

func (m ConcurrentMap) IterBuffered() <-chan Tuple

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

func (ConcurrentMap) IterCb Uses

func (m ConcurrentMap) IterCb(fn IterCb)

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

func (ConcurrentMap) Keys Uses

func (m ConcurrentMap) Keys() []string

Keys Return all keys as []string

func (ConcurrentMap) MSet Uses

func (m ConcurrentMap) MSet(data map[string]interface{})

MSet set data

func (ConcurrentMap) MarshalJSON Uses

func (m ConcurrentMap) MarshalJSON() ([]byte, error)

MarshalJSON Reviles ConcurrentMap "private" variables to json marshal.

func (ConcurrentMap) Pop Uses

func (m ConcurrentMap) Pop(key string) (v interface{}, exists bool)

Pop Removes an element from the map and returns it

func (ConcurrentMap) Remove Uses

func (m ConcurrentMap) Remove(key string)

Remove Removes an element from the map.

func (ConcurrentMap) RemoveCb Uses

func (m ConcurrentMap) RemoveCb(key string, cb RemoveCb) 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 (ConcurrentMap) Set Uses

func (m ConcurrentMap) Set(key string, value interface{})

Set Sets the given value under the specified key.

func (ConcurrentMap) SetIfAbsent Uses

func (m ConcurrentMap) SetIfAbsent(key string, value interface{}) bool

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

func (ConcurrentMap) Upsert Uses

func (m ConcurrentMap) Upsert(key string, value interface{}, cb UpsertCb) (res interface{})

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

type ConcurrentMapShared Uses

type ConcurrentMapShared 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 Uses

type IterCb func(key string, v interface{})

IterCb Iterator callback,called 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 Uses

type RemoveCb func(key string, v interface{}, 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 Tuple Uses

type Tuple struct {
    Key string
    Val interface{}
}

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

type UpsertCb Uses

type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}

UpsertCb 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

Package cmap imports 2 packages (graph) and is imported by 10 packages. Updated 2019-05-19. Refresh now. Tools for package owners.