diff options
author | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:17:02 -0700 |
---|---|---|
committer | Luke Shumaker <lukeshu@lukeshu.com> | 2023-02-12 16:17:02 -0700 |
commit | cfcc753dc8906817e15b1b7c36b4dc12462d12e4 (patch) | |
tree | f5d2aa0caaa4cb336017ba7595c3425f4aa00bfc /lib/containers/sortedmap.go | |
parent | 29b6b9f997913f13a0bff8bb1278a61302413615 (diff) | |
parent | f76faa4b8debd9c94751a03dd65e46c80a340a82 (diff) |
Merge branch 'lukeshu/fast'
Diffstat (limited to 'lib/containers/sortedmap.go')
-rw-r--r-- | lib/containers/sortedmap.go | 9 |
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, |