Skip to content

Commit

Permalink
add (xsync.Map).{CompareAndSwap,CompareAndDelete,Swap}
Browse files Browse the repository at this point in the history
  • Loading branch information
bradenaw committed Sep 11, 2023
1 parent bed6bf7 commit c0ce374
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions xsync/xsync.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,12 @@ type Map[K comparable, V any] struct {
m sync.Map
}

func (m *Map[K, V]) CompareAndDelete(key K, old V) (deleted bool) {
return m.m.CompareAndDelete(key, old)
}
func (m *Map[K, V]) CompareAndSwap(key K, old V, new V) (deleted bool) {
return m.m.CompareAndSwap(key, old, new)
}
func (m *Map[K, V]) Delete(key K) {
m.m.Delete(key)
}
Expand Down Expand Up @@ -261,6 +267,10 @@ func (m *Map[K, V]) Range(f func(key K, value V) bool) {
func (m *Map[K, V]) Store(key K, value V) {
m.m.Store(key, value)
}
func (m *Map[K, V]) Swap(key K, value V) (previous V, loaded bool) {
previousUntyped, loaded := m.m.Swap(key, value)
return previousUntyped.(V), loaded
}

// Pool is a typesafe wrapper over sync.Pool.
type Pool[T any] struct {
Expand Down

0 comments on commit c0ce374

Please sign in to comment.