Documentation ¶
Index ¶
- type ConcurrentHashMap
- func (m *ConcurrentHashMap) AddIfPresent(key uint, value interface{}) bool
- func (m *ConcurrentHashMap) AddIfPresentWithFun(key uint, newVal interface{}, fn fun)
- func (m *ConcurrentHashMap) Count() int
- func (m *ConcurrentHashMap) Erase()
- func (m *ConcurrentHashMap) Get(key uint) (interface{}, bool)
- func (m *ConcurrentHashMap) GetShard(key uint) *ConcurrentMapShared
- func (m *ConcurrentHashMap) Has(key uint) bool
- func (m *ConcurrentHashMap) IsEmpty() bool
- func (m *ConcurrentHashMap) Items() map[uint]interface{}
- func (m *ConcurrentHashMap) Iter() <-chan Tupledeprecated
- func (m *ConcurrentHashMap) IterBuffered() <-chan Tuple
- func (m *ConcurrentHashMap) IterCb(fn IterCb)
- func (m *ConcurrentHashMap) Keys() []uint
- func (m *ConcurrentHashMap) MSet(data map[uint]interface{})
- func (m *ConcurrentHashMap) MarshalJSON() ([]byte, error)
- func (m *ConcurrentHashMap) Pop(key uint) (v interface{}, exists bool)
- func (m *ConcurrentHashMap) Remove(key uint)
- func (m *ConcurrentHashMap) Set(key uint, value interface{})
- func (m *ConcurrentHashMap) SetIfAbsent(key uint, value interface{}) bool
- func (m *ConcurrentHashMap) SetIfPresent(key uint, newValue, oldValue interface{}) bool
- func (m *ConcurrentHashMap) Upsert(key uint, value interface{}, cb UpsertCb) (res interface{})
- type ConcurrentMap
- type ConcurrentMapShared
- type IterCb
- type Tuple
- type UpsertCb
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentHashMap ¶
type ConcurrentHashMap struct { Shards int HashMap ConcurrentMap }
func (*ConcurrentHashMap) AddIfPresent ¶
func (m *ConcurrentHashMap) AddIfPresent(key uint, value interface{}) bool
Sets the given value under the specified key if oldValue was associated with it.
func (*ConcurrentHashMap) AddIfPresentWithFun ¶ added in v1.0.1
func (m *ConcurrentHashMap) AddIfPresentWithFun(key uint, newVal interface{}, fn fun)
func (*ConcurrentHashMap) Count ¶
func (m *ConcurrentHashMap) Count() int
Returns the number of elements within the map.
func (*ConcurrentHashMap) Erase ¶ added in v1.0.1
func (m *ConcurrentHashMap) Erase()
Removes an element from the map.
func (*ConcurrentHashMap) Get ¶
func (m *ConcurrentHashMap) Get(key uint) (interface{}, bool)
Retrieves an element from map under given key.
func (*ConcurrentHashMap) GetShard ¶
func (m *ConcurrentHashMap) GetShard(key uint) *ConcurrentMapShared
Returns shard under given key
func (*ConcurrentHashMap) Has ¶
func (m *ConcurrentHashMap) Has(key uint) bool
Looks up an item under specified key
func (*ConcurrentHashMap) IsEmpty ¶
func (m *ConcurrentHashMap) IsEmpty() bool
Checks if map is empty.
func (*ConcurrentHashMap) Items ¶
func (m *ConcurrentHashMap) Items() map[uint]interface{}
Returns all items as map[uint]interface{}
func (*ConcurrentHashMap) Iter
deprecated
func (m *ConcurrentHashMap) Iter() <-chan Tuple
Returns an iterator which could be used in a for range loop.
Deprecated: using IterBuffered() will get a better performence
func (*ConcurrentHashMap) IterBuffered ¶
func (m *ConcurrentHashMap) IterBuffered() <-chan Tuple
Returns a buffered iterator which could be used in a for range loop.
func (*ConcurrentHashMap) IterCb ¶
func (m *ConcurrentHashMap) IterCb(fn IterCb)
Callback based iterator, cheapest way to read all elements in a map.
func (*ConcurrentHashMap) Keys ¶
func (m *ConcurrentHashMap) Keys() []uint
Return all keys as []uint
func (*ConcurrentHashMap) MSet ¶
func (m *ConcurrentHashMap) MSet(data map[uint]interface{})
Sets the given map
func (*ConcurrentHashMap) MarshalJSON ¶
func (m *ConcurrentHashMap) MarshalJSON() ([]byte, error)
Reviles ConcurrentHashMap "private" variables to json marshal.
func (*ConcurrentHashMap) Pop ¶
func (m *ConcurrentHashMap) Pop(key uint) (v interface{}, exists bool)
Removes an element from the map and returns it
func (*ConcurrentHashMap) Remove ¶
func (m *ConcurrentHashMap) Remove(key uint)
Removes an element from the map.
func (*ConcurrentHashMap) Set ¶
func (m *ConcurrentHashMap) Set(key uint, value interface{})
Sets the given value under the specified key.
func (*ConcurrentHashMap) SetIfAbsent ¶
func (m *ConcurrentHashMap) SetIfAbsent(key uint, value interface{}) bool
Sets the given value under the specified key if no value was associated with it.
func (*ConcurrentHashMap) SetIfPresent ¶
func (m *ConcurrentHashMap) SetIfPresent(key uint, newValue, oldValue interface{}) bool
Sets the given value under the specified key if oldValue was associated with it.
func (*ConcurrentHashMap) Upsert ¶
func (m *ConcurrentHashMap) Upsert(key uint, value interface{}, cb UpsertCb) (res interface{})
Insert or Update - updates existing element or inserts a new one using UpsertCb
type ConcurrentMap ¶
type ConcurrentMap []*ConcurrentMapShared
A "thread" safe map of type uint:Anything. To avoid lock bottlenecks this map is dived to several (Shards) map shards.
type ConcurrentMapShared ¶
type ConcurrentMapShared struct { // contains filtered or unexported fields }
A "thread" safe uint to anything map.
type IterCb ¶
type IterCb func(key uint, v interface{})
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 Tuple ¶
type Tuple struct { Key uint Val interface{} }
Used by the Iter & IterBuffered functions to wrap two variables together over a channel,
type UpsertCb ¶
type UpsertCb func(exist bool, valueInMap interface{}, newValue interface{}) interface{}
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