Skip to content

Commit

Permalink
up
Browse files Browse the repository at this point in the history
  • Loading branch information
mayiweb committed Nov 3, 2022
1 parent bfff649 commit abbf3fe
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions safe/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ func (p *Map) Set(name interface{}, value interface{}) {
// 获取 map
func (p *Map) Get(name interface{}) (interface{}, bool) {

p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

mVal, mOk := p.Map[name]
if !mOk {
Expand Down Expand Up @@ -67,16 +67,16 @@ func (p *Map) Clear() {

// 数据条数
func (p *Map) Size() int {
p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

return len(p.Map)
}

// 获取全部 map
func (p *Map) GetAll() map[interface{}]interface{} {
p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

list := p.Map

Expand Down Expand Up @@ -105,8 +105,8 @@ func (p *Map2) Set(key1 interface{}, key2 interface{}, value interface{}) {
// 获取 map
func (p *Map2) Get(key1 interface{}, key2 interface{}) (interface{}, bool) {

p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

mVal, mOk := p.Map[key1][key2]
if !mOk {
Expand All @@ -118,8 +118,8 @@ func (p *Map2) Get(key1 interface{}, key2 interface{}) (interface{}, bool) {

// 获取二级 key 列表
func (p *Map2) GetList(key1 interface{}) (map[interface{}]interface{}, bool) {
p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

mVal, mOk := p.Map[key1]
if !mOk {
Expand All @@ -131,8 +131,8 @@ func (p *Map2) GetList(key1 interface{}) (map[interface{}]interface{}, bool) {

// 获取二级 key 列数据条数
func (p *Map2) GetListSize(key1 interface{}) int {
p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

_, mOk := p.Map[key1]
if !mOk {
Expand Down Expand Up @@ -171,16 +171,16 @@ func (p *Map2) Clear() {

// 数据条数
func (p *Map2) Size() int {
p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

return len(p.Map)
}

// 获取全部 map
func (p *Map2) GetAll() map[interface{}]map[interface{}]interface{} {
p.Lock.Lock()
defer p.Lock.Unlock()
p.Lock.RLock()
defer p.Lock.RUnlock()

return p.Map
}

0 comments on commit abbf3fe

Please sign in to comment.