Atlas › Test

TestSortedSetManager_Remove

Exact test identity: go.temporal.io/server/common/collection/TestSortedSetManager_Remove

Package
go.temporal.io/server/common/collection
Suite / test hierarchy
TestSortedSetManager_Remove
Test
TestSortedSetManager_Remove
Introduced at
sorted_set_manager.go ×1 Frontier kind: Joint frontier
Covered ranges
5
Covered lines
16
Covered files
1

Covered source

Expand a file to inspect source; the > gutter marks covered lines.

go.temporal.io/server/common/collection/sorted_set_manager.go 16 covered LOC · 5 ranges

Open complete file

11
12 // NewSortedSetManager returns a new SortedSetManager with the given comparison function and key function.
13 > func NewSortedSetManager[S ~[]E, E, K any](cmp func(E, K) int, key func(E) K) SortedSetManager[S, E, K] { sorted_set_manager.go
14 > return SortedSetManager[S, E, K]{cmp, key}
15 > }
16
17 // Add adds a new element to the set. If the element is already in the set, it returns the set unchanged and false.
18 > func (m SortedSetManager[S, E, K]) Add(set S, e E) (S, bool) { sorted_set_manager.go
19 > i, found := m.find(set, m.key(e))
20 > if found {
21 return set, false
22 }
23 > return slices.Insert(set, i, e), true sorted_set_manager.go
24 }
25
55
56 // Remove removes an element from the set. If the element is not in the set, it returns the set unchanged and false.
57 > func (m SortedSetManager[S, E, K]) Remove(set S, key K) (S, bool) { sorted_set_manager.go
58 > i, found := m.find(set, key)
59 > if !found {
60 > return set, false
61 > }
62 > return slices.Delete(set, i, i+1), true
63 }
64
65 > func (m SortedSetManager[S, E, K]) find(set S, key K) (int, bool) { sorted_set_manager.go
66 > return slices.BinarySearchFunc(set, key, m.cmp)
67 > }