summaryrefslogtreecommitdiff
path: root/lib/containers/rbtree.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2022-12-20 20:06:15 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2022-12-20 20:06:15 -0700
commit8ff81c1ed6a50179166ffc4cfb60bef85394265e (patch)
treef2395593d4d4cfd12b26ba2030bb94930fe4ba56 /lib/containers/rbtree.go
parent7315c38414b3a6840d71f254b7c8192640b41d7c (diff)
parent94a86a763157327ac969c98e19d7770db477a6a3 (diff)
Merge branch 'lukeshu/rebuild-nodes-take2'
Diffstat (limited to 'lib/containers/rbtree.go')
-rw-r--r--lib/containers/rbtree.go7
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/containers/rbtree.go b/lib/containers/rbtree.go
index ab79a26..e2d8f8a 100644
--- a/lib/containers/rbtree.go
+++ b/lib/containers/rbtree.go
@@ -37,6 +37,11 @@ type RBTree[K Ordered[K], V any] struct {
KeyFn func(V) K
AttrFn func(*RBNode[V])
root *RBNode[V]
+ len int
+}
+
+func (t *RBTree[K, V]) Len() int {
+ return t.len
}
func (t *RBTree[K, V]) Walk(fn func(*RBNode[V]) error) error {
@@ -324,6 +329,7 @@ func (t *RBTree[K, V]) Insert(val V) {
exact.Value = val
return
}
+ t.len++
node := &RBNode[V]{
Color: Red,
@@ -394,6 +400,7 @@ func (t *RBTree[K, V]) Delete(key K) {
if nodeToDelete == nil {
return
}
+ t.len--
// This is closely based on the algorithm presented in CLRS
// 3e.