1
0
mirror of https://github.com/fluencelabs/tendermint synced 2025-06-28 12:11:44 +00:00
Files
.circleci
.github
DOCKER
abci
benchmarks
blockchain
cmd
config
consensus
crypto
docs
evidence
libs
autofile
bech32
cli
clist
common
LICENSE
async.go
async_test.go
bit_array.go
bit_array_test.go
bytes.go
bytes_test.go
byteslice.go
byteslice_test.go
cmap.go
cmap_test.go
colors.go
date.go
date_test.go
errors.go
errors_test.go
heap.go
int.go
int_test.go
io.go
kvpair.go
math.go
net.go
net_test.go
nil.go
os.go
os_test.go
random.go
random_test.go
repeat_timer.go
repeat_timer_test.go
service.go
service_test.go
string.go
string_test.go
throttle_timer.go
throttle_timer_test.go
types.pb.go
types.proto
word.go
db
events
flowrate
log
pubsub
test
version
.editorconfig
.gitignore
CHANGELOG.md
README.md
circle.yml
test.sh
lite
mempool
networks
node
p2p
privval
proxy
rpc
scripts
state
test
types
version
.editorconfig
.gitignore
CHANGELOG.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
Gopkg.lock
Gopkg.toml
LICENSE
Makefile
README.md
ROADMAP.md
SECURITY.md
Vagrantfile
appveyor.yml
codecov.yml
docker-compose.yml
tendermint/libs/common/cmap.go

74 lines
1.1 KiB
Go
Raw Normal View History

2015-10-21 12:15:19 -07:00
package common
import "sync"
// CMap is a goroutine-safe map
type CMap struct {
m map[string]interface{}
l sync.Mutex
}
func NewCMap() *CMap {
return &CMap{
m: make(map[string]interface{}),
2015-10-21 12:15:19 -07:00
}
}
func (cm *CMap) Set(key string, value interface{}) {
cm.l.Lock()
defer cm.l.Unlock()
cm.m[key] = value
}
func (cm *CMap) Get(key string) interface{} {
cm.l.Lock()
defer cm.l.Unlock()
return cm.m[key]
}
func (cm *CMap) Has(key string) bool {
cm.l.Lock()
defer cm.l.Unlock()
_, ok := cm.m[key]
return ok
}
func (cm *CMap) Delete(key string) {
cm.l.Lock()
defer cm.l.Unlock()
delete(cm.m, key)
}
func (cm *CMap) Size() int {
cm.l.Lock()
defer cm.l.Unlock()
return len(cm.m)
}
func (cm *CMap) Clear() {
cm.l.Lock()
defer cm.l.Unlock()
cm.m = make(map[string]interface{})
2015-10-21 12:15:19 -07:00
}
func (cm *CMap) Keys() []string {
cm.l.Lock()
defer cm.l.Unlock()
keys := []string{}
for k := range cm.m {
keys = append(keys, k)
}
return keys
}
2015-10-21 12:15:19 -07:00
func (cm *CMap) Values() []interface{} {
cm.l.Lock()
defer cm.l.Unlock()
items := []interface{}{}
for _, v := range cm.m {
items = append(items, v)
}
return items
}