diff --git a/xsync/xsync.go b/xsync/xsync.go index ae83783..445862a 100644 --- a/xsync/xsync.go +++ b/xsync/xsync.go @@ -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) } @@ -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 {