Documentation ¶
Index ¶
- type ConcurrentMap
- func (m *ConcurrentMap) Count() int
- func (m *ConcurrentMap) Get(key uint16) (interface{}, bool)
- func (m *ConcurrentMap) Has(key uint16) bool
- func (m *ConcurrentMap) HasAll(keys []uint16) bool
- func (m *ConcurrentMap) HasAny(keys []uint16) bool
- func (m *ConcurrentMap) IsEmpty() bool
- func (m *ConcurrentMap) Items() map[uint16]interface{}
- func (m *ConcurrentMap) Iter() <-chan Tupledeprecated
- func (m *ConcurrentMap) IterBuffered() <-chan Tuple
- func (m *ConcurrentMap) IterCb(fn IterCb)
- func (m *ConcurrentMap) Keys() []uint16
- func (m *ConcurrentMap) MGet(keys []uint16) map[uint16]interface{}
- func (m *ConcurrentMap) MRemove(keys []uint16)
- func (m *ConcurrentMap) MRemoveCb(keys []uint16, cb RemoveCb)
- func (m *ConcurrentMap) MSet(data map[uint16]interface{})
- func (m *ConcurrentMap) MSetIfAbsent(data map[uint16]interface{}) []uint16
- func (m *ConcurrentMap) MSetIfAllAbsent(data map[uint16]interface{}) bool
- func (m *ConcurrentMap) MarshalJSON() ([]byte, error)
- func (m *ConcurrentMap) Pop(key uint16) (v interface{}, exists bool)
- func (m *ConcurrentMap) Remove(key uint16)
- func (m *ConcurrentMap) RemoveCb(key uint16, cb RemoveCb) bool
- func (m *ConcurrentMap) Set(key uint16, value interface{})
- func (m *ConcurrentMap) SetIfAbsent(key uint16, value interface{}) bool
- func (m *ConcurrentMap) Upsert(key uint16, value interface{}, cb UpsertCb) (res interface{})
- type ConcurrentMapShared
- type IterCb
- type RemoveCb
- type Tuple
- type UpsertCb
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type ConcurrentMap ¶
type ConcurrentMap struct {
// contains filtered or unexported fields
}
A "thread" safe map of type uint16:Anything. To avoid lock bottlenecks this map is dived to several (shardCount) map shards.
func NewDefault ¶
func NewDefault() *ConcurrentMap
func (*ConcurrentMap) Count ¶
func (m *ConcurrentMap) Count() int
Returns the number of elements within the map.
func (*ConcurrentMap) Get ¶
func (m *ConcurrentMap) Get(key uint16) (interface{}, bool)
Retrieves an element from map under given key.
func (*ConcurrentMap) Has ¶
func (m *ConcurrentMap) Has(key uint16) bool
Looks up an item under specified key
func (*ConcurrentMap) HasAll ¶
func (m *ConcurrentMap) HasAll(keys []uint16) bool
func (*ConcurrentMap) HasAny ¶
func (m *ConcurrentMap) HasAny(keys []uint16) bool
func (*ConcurrentMap) Items ¶
func (m *ConcurrentMap) Items() map[uint16]interface{}
Returns all items as map[uint16]interface{}
func (*ConcurrentMap) Iter
deprecated
func (m *ConcurrentMap) Iter() <-chan Tuple
Returns an iterator which could be used in a for range loop.
Deprecated: using IterBuffered() will get a better performance
func (*ConcurrentMap) IterBuffered ¶
func (m *ConcurrentMap) IterBuffered() <-chan Tuple
Returns a buffered iterator which could be used in a for range loop.
func (*ConcurrentMap) IterCb ¶
func (m *ConcurrentMap) IterCb(fn IterCb)
Callback based iterator, cheapest way to read all elements in a map.
func (*ConcurrentMap) MGet ¶
func (m *ConcurrentMap) MGet(keys []uint16) map[uint16]interface{}
func (*ConcurrentMap) MRemove ¶
func (m *ConcurrentMap) MRemove(keys []uint16)
func (*ConcurrentMap) MRemoveCb ¶
func (m *ConcurrentMap) MRemoveCb(keys []uint16, cb RemoveCb)
func (*ConcurrentMap) MSet ¶
func (m *ConcurrentMap) MSet(data map[uint16]interface{})
func (*ConcurrentMap) MSetIfAbsent ¶
func (m *ConcurrentMap) MSetIfAbsent(data map[uint16]interface{}) []uint16
MSetIfAbsent sets the given value only if key has no value associated with it.
func (*ConcurrentMap) MSetIfAllAbsent ¶
func (m *ConcurrentMap) MSetIfAllAbsent(data map[uint16]interface{}) bool
func (*ConcurrentMap) MarshalJSON ¶
func (m *ConcurrentMap) MarshalJSON() ([]byte, error)
Reviles ConcurrentMap "private" variables to json marshal.
func (*ConcurrentMap) Pop ¶
func (m *ConcurrentMap) Pop(key uint16) (v interface{}, exists bool)
Removes an element from the map and returns it
func (*ConcurrentMap) Remove ¶
func (m *ConcurrentMap) Remove(key uint16)
Removes an element from the map.
func (*ConcurrentMap) RemoveCb ¶
func (m *ConcurrentMap) RemoveCb(key uint16, 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 ¶
func (m *ConcurrentMap) Set(key uint16, value interface{})
Sets the given value under the specified key.
func (*ConcurrentMap) SetIfAbsent ¶
func (m *ConcurrentMap) SetIfAbsent(key uint16, value interface{}) bool
Sets the given value under the specified key if no value was associated with it.
func (*ConcurrentMap) Upsert ¶
func (m *ConcurrentMap) Upsert(key uint16, value interface{}, cb UpsertCb) (res interface{})
Insert or Update - updates existing element or inserts a new one using UpsertCb
type ConcurrentMapShared ¶
type ConcurrentMapShared struct {
// contains filtered or unexported fields
}
A "thread" safe uint16 to anything map.
type IterCb ¶
type IterCb func(key uint16, 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 RemoveCb ¶
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 ¶
type Tuple struct { Key uint16 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