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.
19
>
i, found := m.find(set, m.key(e))
20
>
if found {
21
return set, false
22
}
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.
28
>
i, found := m.find(set, key)
29
>
if !found {
30
>
return -1
31
>
}
32
>
return i
33
}
34