You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sync.Map gained Swap in Go 1.20 and Clear in Go 1.23. The fork wraps neither. Add both as methods on SyncMap[K, V], matching the stdlib signatures and contracts exactly. Unit tests ship in the same PR; benchmarks land in #12 and BDD scenarios in #13.
Requirements
Add func (m *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool) in syncmap.go. Wraps sync.Map.Swap. Return the typed zero V if loaded == false.
Add func (m *SyncMap[K, V]) Clear() in syncmap.go. Wraps sync.Map.Clear. Removes all entries.
feat: add Swap and Clear methods
Summary
sync.MapgainedSwapin Go 1.20 andClearin Go 1.23. The fork wraps neither. Add both as methods onSyncMap[K, V], matching the stdlib signatures and contracts exactly. Unit tests ship in the same PR; benchmarks land in #12 and BDD scenarios in #13.Requirements
func (m *SyncMap[K, V]) Swap(key K, value V) (previous V, loaded bool)insyncmap.go. Wrapssync.Map.Swap. Return the typed zero V ifloaded == false.func (m *SyncMap[K, V]) Clear()insyncmap.go. Wrapssync.Map.Clear. Removes all entries.syncmap_test.go:TestSwap— subtests:absent_returns_zero_V_loaded_false_and_stores,present_returns_old_loaded_true_and_overwrites,zero_V_distinguished_from_absent(critical — useSyncMap[string, int]).TestClear— subtests:empty_map_noop,populated_map_becomes_empty,subsequent_Store_works.TestSwapContention— 100 goroutines same key; countloaded==falseviaatomic.Int32; assert exactly one.Acceptance Criteria
grep -nE 'func \(m \*SyncMap\[K, V\]\) Swap\(' syncmap.goreturns exactly one match.grep -nE 'func \(m \*SyncMap\[K, V\]\) Clear\(' syncmap.goreturns exactly one match.go doc github.com/axonops/syncmap Swapprints non-empty godoc; same forClear.go test -race -run 'TestSwap|TestClear|TestSwapContention' -count=10 ./...passes stably over 10 repetitions.make coveragereports ≥95% including the new methods.make checkpasses end-to-end.Testing Requirements
syncmap_test.go.-count=10repetition on the concurrency test.make checkgreen.SwapandClearare owned by feat!: rename Items to Values #12 and may be deferred — not blocking here.SwapandClearare owned by feat: add Swap and Clear methods #13 and may be deferred — not blocking here.Documentation Requirements
Dependencies
Labels
enhancementP1