Atlas › Test

TestSortedSetManager_Get

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

Package
go.temporal.io/server/common/collection
Suite / test hierarchy
TestSortedSetManager_Get
Test
TestSortedSetManager_Get
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
26 // Get returns the index of the element in the set that compares equal to key or -1 if no such element exists.
27 > func (m SortedSetManager[S, E, K]) Get(set S, key K) int { sorted_set_manager.go
28 > i, found := m.find(set, key)
29 > if !found {
30 > return -1
31 > }
32 > return i
33 }
34
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 > }