Skip to content

Commit

Permalink
add map len
Browse files Browse the repository at this point in the history
  • Loading branch information
mazrean committed Feb 26, 2023
1 parent 6c70109 commit 850fba3
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cache/sc.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,13 @@ func (m *Map[K, V]) Store(key K, value V) {
m.locker.Unlock()
}

func (m *Map[K, V]) Len() int {
m.locker.RLock()
l := len(m.m)
m.locker.RUnlock()
return l
}

func (m *Map[K, V]) Update(key K, f func(V) (V, bool)) {
m.locker.Lock()
v, ok := f(m.m[key])
Expand Down Expand Up @@ -376,6 +383,14 @@ func (m *AtomicMap[K, V, T]) Store(key K, value V) {
}
}

func (m *AtomicMap[K, V, T]) Len() int {
m.locker.RLock()
l := len(m.m)
m.locker.RUnlock()

return l
}

func (m *AtomicMap[K, V, T]) Update(key K, f func(V) (V, bool)) {
m.locker.Lock()
v, ok := f(m.m[key].Load())
Expand Down

0 comments on commit 850fba3

Please sign in to comment.