Skip to content

Commit 7ea27fe

Browse files
committed
concurrent map update
1 parent 942fb88 commit 7ea27fe

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lib/db/types/map.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ func (m Map[K, V]) Get(key K) (V, bool) {
116116
return val, ok
117117
}
118118

119+
// Exists checks if a key exists in the map
120+
func (m Map[K, V]) Exists(key K) bool {
121+
shard := m.GetShard(key)
122+
shard.RLock()
123+
_, ok := shard.items[key]
124+
shard.RUnlock()
125+
return ok
126+
}
127+
119128
// Remove deletes a key-value pair from the map.
120129
func (m Map[K, V]) Remove(key K) {
121130
shard := m.GetShard(key)

0 commit comments

Comments
 (0)