Skip to content

Commit

Permalink
concurrent map update
Browse files Browse the repository at this point in the history
  • Loading branch information
iesreza committed Jan 1, 2025
1 parent 942fb88 commit 7ea27fe
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/db/types/map.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,15 @@ func (m Map[K, V]) Get(key K) (V, bool) {
return val, ok
}

// Exists checks if a key exists in the map
func (m Map[K, V]) Exists(key K) bool {
shard := m.GetShard(key)
shard.RLock()
_, ok := shard.items[key]
shard.RUnlock()
return ok
}

// Remove deletes a key-value pair from the map.
func (m Map[K, V]) Remove(key K) {
shard := m.GetShard(key)
Expand Down

0 comments on commit 7ea27fe

Please sign in to comment.