From 9fba52ee79c04580ab6c7fa589cfb7b58a545ded Mon Sep 17 00:00:00 2001 From: "carpentry-heartbeat[bot]" Date: Wed, 10 Jun 2026 11:40:56 +0200 Subject: [PATCH] Update docs to reflect AVL tree in ordered map/set PR #5 replaced the unbalanced BST with a self-balancing AVL tree, but the design doc and persistent_docs.carp still described the old implementation. This brings the documentation in line with the code. --- docs/design.md | 12 +++++++----- persistent_docs.carp | 2 +- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/docs/design.md b/docs/design.md index 445fbea..d72d1e0 100644 --- a/docs/design.md +++ b/docs/design.md @@ -64,11 +64,14 @@ indexed differently. ### Ordered map and set -A persistent binary search tree. Insert/remove path-copy from the root to the -leaf. Two-child delete uses successor-from-right. +A persistent AVL tree (self-balancing binary search tree). Insert/remove +path-copy from the root to the leaf and rebalance on the way back up. +Two-child delete uses successor-from-right. Each node stores a height field +used to compute balance factors; single and double rotations keep the tree +within AVL balance (height difference of at most 1 between subtrees). -The tree is intentionally unbalanced. Random-ish input behaves; worst-case -input (always increasing) degrades to a list. +This guarantees O(log n) insert, remove, and lookup regardless of insertion +order. ### Heap @@ -136,7 +139,6 @@ likely offenders. ## What's deliberately not here yet -- balanced ordered map (AVL/RB) - finger-tree-based deque scheduling - adaptive hash-trie depth - structural `=` for the heap diff --git a/persistent_docs.carp b/persistent_docs.carp index 89814af..165015b 100644 --- a/persistent_docs.carp +++ b/persistent_docs.carp @@ -27,7 +27,7 @@ dispatch. - **Queue**: two-list FIFO with amortized O(1) ends. - **Deque**: two-list double-ended queue. - **Trie**: keyed by `(Array K)`, supports prefix queries. -- **Ordered map / set**: unbalanced persistent BST. +- **Ordered map / set**: persistent AVL tree (self-balancing BST). - **Heap**: persistent skew min-heap. Everything is `merge`. - **Hash map / set**: trie keyed by hash digits (depth 8, radix 16). - **Vector**: trie keyed by index digits (depth 7, radix 32).