cmap

package
v0.0.0-...-b6f14a9 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2018 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultShardCount = 32

DefaultShardCount represents the default count of shard.

Functions

This section is empty.

Types

type ConcurrentMap

type ConcurrentMap struct {
	// contains filtered or unexported fields
}

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

func New

func New(shardCnt uint) ConcurrentMap

New creates a new concurrent map.

func (ConcurrentMap) Count

func (m ConcurrentMap) Count() int

Count returns the number of elements within the map.

func (ConcurrentMap) Get

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

Get retrieves an element from map under given key.

func (ConcurrentMap) GetShard

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

GetShard returns shard under given key

func (*ConcurrentMap) Has

func (m *ConcurrentMap) Has(key string) bool

Has looks up an item under specified key

func (*ConcurrentMap) IsEmpty

func (m *ConcurrentMap) IsEmpty() bool

IsEmpty checks if map is empty.

func (ConcurrentMap) Items

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

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

func (ConcurrentMap) Iter

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

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

func (ConcurrentMap) IterBuffered

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

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

func (ConcurrentMap) MarshalJSON

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

MarshalJSON implements the Marshaler interface.

func (*ConcurrentMap) Remove

func (m *ConcurrentMap) Remove(key string)

Remove removes an element from the map.

func (*ConcurrentMap) Set

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

Set sets the given value under the specified key.

func (*ConcurrentMap) SetIfAbsent

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.

type ConcurrentMapShared

type ConcurrentMapShared struct {
	sync.RWMutex // Read Write mutex, guards access to internal map.
	// contains filtered or unexported fields
}

ConcurrentMapShared represents a "thread" safe string to anything map.

type Tuple

type Tuple struct {
	Key string
	Val interface{}
}

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

Jump to

Keyboard shortcuts

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