Skip to content

60 add avl tree as an alternative backend data structures for copy efficent persistent data structures#61

Open
kaizhx wants to merge 4 commits into
mainfrom
60-add-avl-tree-as-an-alternative-backend-data-structures-for-copy-efficent-persistent-data-structures
Open

60 add avl tree as an alternative backend data structures for copy efficent persistent data structures#61
kaizhx wants to merge 4 commits into
mainfrom
60-add-avl-tree-as-an-alternative-backend-data-structures-for-copy-efficent-persistent-data-structures

Conversation

@kaizhx
Copy link
Copy Markdown

@kaizhx kaizhx commented May 13, 2026

Summary

Adds an initial path-copying persistent AVL tree map implementation based on the existing PathCopyingPersistentTreeMap which is based on a LLRB tree.

Changes

Changes to the existing tree map implementation focus on replacing LLRB specific logic with their AVL counterparts:

  • Added PathCopyingPersistentAvlTreeMap
  • Replaced color metadata stored in nodes with AVL height metadata.
  • Added AVL balance factor calculation based on subtree heights.
  • Replaced LLRB invariant restoration with AVL rebalancing via rebalance().
  • Implemented trinode restructuring for simplified rebalancing logic via restructure().
    (See https://www.csl.mtu.edu/cs2321/www/newLectures/20_AVL_Tree.html for more information on restructuring algorithm)
  • Updated checkAssertions() to validate AVL height and balance invariants instead of LLRB invariants.
  • Reworked insertion via putAndCopy() to use AVL rebalancing.
  • Reworked deletion via removeAndCopy() to use standard BST deletion followed by AVL rebalancing.
  • Implemented Browns improved deletion algorithm for AVL trees in restructure() for the two child deletion case, choosing the predecessor/successor replacement based on the larger subtree height.
    (See https://arxiv.org/pdf/2406.05162 for Browns improved deletion algorithm)

Reused structures

The implementation intentionally keeps most of the existing persistent tree map structure unchanged where logic is not tied to the LLRB tree implementation and only requires the existence of a binary search tree.

  • Immutable node structure
  • Empty map handling
  • Persistent path-copying style
  • Entry iteration
  • helper functions (min/max node, lookup, bounds)
  • Bounded views support (e.g. subMap, headMap, tailMap)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Add AVL Tree as an Alternative Backend Data-Structures for Copy-Efficent (Persistent) Data-Structures

1 participant