|
|
@ -32,37 +32,54 @@ func (stack *StarStack) MustPop() interface{} {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Get(key string) (interface{}, error) {
|
|
|
|
func Get(key string) (interface{}, error) {
|
|
|
|
|
|
|
|
return globalMap.Get(key)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *StarMapKV) Get(key string) (interface{}, error) {
|
|
|
|
var err error
|
|
|
|
var err error
|
|
|
|
kvmu.RLock()
|
|
|
|
m.kvmu.RLock()
|
|
|
|
defer kvmu.RUnlock()
|
|
|
|
defer m.kvmu.RUnlock()
|
|
|
|
data, ok := kvMap[key]
|
|
|
|
data, ok := m.kvMap[key]
|
|
|
|
if !ok {
|
|
|
|
if !ok {
|
|
|
|
err = errors.New("key not exists")
|
|
|
|
err = errors.New("key not exists")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return data, err
|
|
|
|
return data, err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func MustGet(key string) interface{} {
|
|
|
|
func (m *StarMapKV) MustGet(key string) interface{} {
|
|
|
|
result, _ := Get(key)
|
|
|
|
result, _ := m.Get(key)
|
|
|
|
return result
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func MustGet(key string) interface{} {
|
|
|
|
|
|
|
|
return globalMap.MustGet(key)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Store(key string, value interface{}) error {
|
|
|
|
func Store(key string, value interface{}) error {
|
|
|
|
kvmu.Lock()
|
|
|
|
return globalMap.Store(key, value)
|
|
|
|
defer kvmu.Unlock()
|
|
|
|
}
|
|
|
|
kvMap[key] = value
|
|
|
|
func (m *StarMapKV) Store(key string, value interface{}) error {
|
|
|
|
|
|
|
|
m.kvmu.Lock()
|
|
|
|
|
|
|
|
defer m.kvmu.Unlock()
|
|
|
|
|
|
|
|
m.kvMap[key] = value
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Delete(key string) error {
|
|
|
|
func Delete(key string) error {
|
|
|
|
kvmu.Lock()
|
|
|
|
return globalMap.Delete(key)
|
|
|
|
defer kvmu.Unlock()
|
|
|
|
}
|
|
|
|
delete(kvMap, key)
|
|
|
|
func (m *StarMapKV) Delete(key string) error {
|
|
|
|
|
|
|
|
m.kvmu.Lock()
|
|
|
|
|
|
|
|
defer m.kvmu.Unlock()
|
|
|
|
|
|
|
|
delete(m.kvMap, key)
|
|
|
|
return nil
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func Range(run func(k string, v interface{}) bool) error {
|
|
|
|
func Range(run func(k string, v interface{}) bool) error {
|
|
|
|
for k, v := range kvMap {
|
|
|
|
return globalMap.Range(run)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func (m *StarMapKV) Range(run func(k string, v interface{}) bool) error {
|
|
|
|
|
|
|
|
for k, v := range m.kvMap {
|
|
|
|
if !run(k, v) {
|
|
|
|
if !run(k, v) {
|
|
|
|
break
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|