diff --git a/doc.go b/doc.go index 3a807b4..b71a491 100644 --- a/doc.go +++ b/doc.go @@ -27,7 +27,7 @@ // operations — Load, Store, LoadOrStore, LoadAndDelete, Delete, and // Range — with identical semantics and the same concurrency // guarantees. Four convenience methods are added on top: Len, Map, -// Keys, and Items. The underlying sync.Map is not exported; use the +// Keys, and Values. The underlying sync.Map is not exported; use the // typed methods exclusively. // // # When to use SyncMap diff --git a/syncmap.go b/syncmap.go index 8f27cdd..18a4045 100644 --- a/syncmap.go +++ b/syncmap.go @@ -132,7 +132,7 @@ func (m *SyncMap[K, V]) Keys() []K { return keys } -// Items returns a slice of all values present in the map at the +// Values returns a slice of all values present in the map at the // moment of the call. It runs in O(n) time. // // The result is a point-in-time approximation. Concurrent stores and @@ -140,11 +140,11 @@ func (m *SyncMap[K, V]) Keys() []K { // removed, or to omit values that were added during traversal. The // order of values is undefined, and does not correspond to the order // returned by Keys. -func (m *SyncMap[K, V]) Items() []V { - var items []V +func (m *SyncMap[K, V]) Values() []V { + var values []V m.syncMap.Range(func(key, value any) bool { - items = append(items, value.(V)) + values = append(values, value.(V)) return true }) - return items + return values } diff --git a/syncmap_test.go b/syncmap_test.go index 73f042a..c787200 100644 --- a/syncmap_test.go +++ b/syncmap_test.go @@ -357,14 +357,14 @@ func TestKeys(t *testing.T) { }) } -func TestItems(t *testing.T) { +func TestValues(t *testing.T) { t.Parallel() t.Run("empty_is_empty", func(t *testing.T) { t.Parallel() m := &syncmap.SyncMap[string, int]{} - items := m.Items() - assert.Empty(t, items) + values := m.Values() + assert.Empty(t, values) }) t.Run("matches", func(t *testing.T) { @@ -373,9 +373,9 @@ func TestItems(t *testing.T) { m.Store("a", 1) m.Store("b", 2) m.Store("c", 3) - items := m.Items() - sort.Ints(items) - assert.Equal(t, []int{1, 2, 3}, items) + values := m.Values() + sort.Ints(values) + assert.Equal(t, []int{1, 2, 3}, values) }) t.Run("length_equals_len", func(t *testing.T) { @@ -383,7 +383,7 @@ func TestItems(t *testing.T) { m := &syncmap.SyncMap[string, int]{} m.Store("x", 10) m.Store("y", 20) - assert.Equal(t, m.Len(), len(m.Items())) + assert.Equal(t, m.Len(), len(m.Values())) }) }