Search code examples
language-agnosticsearchtreebinary-treefinger-tree

Is there an implementation of a binary search tree annotated with sub-tree size


I have been researching the tree data structure described at this link (near the bottom):

http://sigpipe.macromates.com/2009/08/13/maintaining-a-layout/

It is mentioned that this data structure could be a finger tree. However, after more research around finger trees, I've found that this lacks the "fingers" that makes finger trees finger trees. Instead, it seems this is just an annotated binary tree (annotated with subtree size).

Do you know of an existing implementation (in any language) of this data-structure that I could use as a reference for my own implementation (though, preferably not an implementation in a functional programming language)?

Or, what would be the most optimal way of retrofitting the subtree size annotations into an existing tree data-structure?

Thanks!


Solution

  • Simon Tatham's Counted B-Trees are similar. if the node count is replaced with a width of buffer like in tweak, these provide operations like ropes.

    in fact from reading that the page you reference i see that it was being used like a piece table or line table for an editor

    in the paper, Positional Delta Trees to reconcile updates with read-optimized data storage, the authors present a tree which behavior in regard to the invariants it holds between the nodes in the tree bares a striking resemblance to xanadu's enfilades to which the Counted B-tree is also similar.