|
@ -16,58 +16,60 @@ func NewCMap() *CMap { |
|
|
|
|
|
|
|
|
func (cm *CMap) Set(key string, value interface{}) { |
|
|
func (cm *CMap) Set(key string, value interface{}) { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
cm.m[key] = value |
|
|
cm.m[key] = value |
|
|
|
|
|
cm.l.Unlock() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Get(key string) interface{} { |
|
|
func (cm *CMap) Get(key string) interface{} { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
return cm.m[key] |
|
|
|
|
|
|
|
|
val := cm.m[key] |
|
|
|
|
|
cm.l.Unlock() |
|
|
|
|
|
return val |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Has(key string) bool { |
|
|
func (cm *CMap) Has(key string) bool { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
_, ok := cm.m[key] |
|
|
_, ok := cm.m[key] |
|
|
|
|
|
cm.l.Unlock() |
|
|
return ok |
|
|
return ok |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Delete(key string) { |
|
|
func (cm *CMap) Delete(key string) { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
delete(cm.m, key) |
|
|
delete(cm.m, key) |
|
|
|
|
|
cm.l.Unlock() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Size() int { |
|
|
func (cm *CMap) Size() int { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
return len(cm.m) |
|
|
|
|
|
|
|
|
size := len(cm.m) |
|
|
|
|
|
cm.l.Unlock() |
|
|
|
|
|
return size |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Clear() { |
|
|
func (cm *CMap) Clear() { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
cm.m = make(map[string]interface{}) |
|
|
cm.m = make(map[string]interface{}) |
|
|
|
|
|
cm.l.Unlock() |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Keys() []string { |
|
|
func (cm *CMap) Keys() []string { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
|
|
|
|
|
|
keys := []string{} |
|
|
keys := []string{} |
|
|
for k := range cm.m { |
|
|
for k := range cm.m { |
|
|
keys = append(keys, k) |
|
|
keys = append(keys, k) |
|
|
} |
|
|
} |
|
|
|
|
|
cm.l.Unlock() |
|
|
return keys |
|
|
return keys |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (cm *CMap) Values() []interface{} { |
|
|
func (cm *CMap) Values() []interface{} { |
|
|
cm.l.Lock() |
|
|
cm.l.Lock() |
|
|
defer cm.l.Unlock() |
|
|
|
|
|
items := []interface{}{} |
|
|
items := []interface{}{} |
|
|
for _, v := range cm.m { |
|
|
for _, v := range cm.m { |
|
|
items = append(items, v) |
|
|
items = append(items, v) |
|
|
} |
|
|
} |
|
|
|
|
|
cm.l.Unlock() |
|
|
return items |
|
|
return items |
|
|
} |
|
|
} |