summaryrefslogtreecommitdiff
path: root/lib/containers/sortedmap.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-09 14:23:23 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-12 16:16:53 -0700
commitd91f8ce17a6fc165fafd9dc921911233a69c34d2 (patch)
tree808a86b8f2309fe344b4cb0af62101b8a3b8b59a /lib/containers/sortedmap.go
parent1d7f5446dc37687f078269af3c63af7d7ebbfab4 (diff)
tree-wide: Migrate to the new ARCache
Diffstat (limited to 'lib/containers/sortedmap.go')
-rw-r--r--lib/containers/sortedmap.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/containers/sortedmap.go b/lib/containers/sortedmap.go
index d104274..ebce685 100644
--- a/lib/containers/sortedmap.go
+++ b/lib/containers/sortedmap.go
@@ -17,6 +17,8 @@ type SortedMap[K Ordered[K], V any] struct {
inner RBTree[orderedKV[K, V]]
}
+var _ SubrangeMap[NativeOrdered[int], string] = (*SortedMap[NativeOrdered[int], string])(nil)
+
func (m *SortedMap[K, V]) Delete(key K) {
m.inner.Delete(m.inner.Search(func(kv orderedKV[K, V]) int {
return key.Compare(kv.K)
@@ -34,6 +36,13 @@ func (m *SortedMap[K, V]) Load(key K) (value V, ok bool) {
return node.Value.V, true
}
+func (m *SortedMap[K, V]) Has(key K) bool {
+ node := m.inner.Search(func(kv orderedKV[K, V]) int {
+ return key.Compare(kv.K)
+ })
+ return node != nil
+}
+
func (m *SortedMap[K, V]) Store(key K, value V) {
m.inner.Insert(orderedKV[K, V]{
K: key,