treap 0.1.0
treap: ^0.1.0 copied to clipboard
A persistent treap for Dart. A heap balanced randomized binary tree with efficient value semantics. All operations are O(log n) worst case.
Treap #
A package implementing a persistent (immutable) order statistic tree by means of the treap data structure (a kind of cartesian tree). Apart from the regular set operations, it allows for:
select(i)– find thei-th smallest element.rank(x)– find the rank of elementx, i.e. the number of elements smaller thanx.
both in O(log(N)) time.
This particular implementation is made fully persistent by means of path copying. That is, any operation that would otherwise mutate the treap, instead produces a new treap, and does so using only O(log(N)) extra space.
Example #
A toy todo flutter app, that illustrates how to use persistent treaps to efficiently handle undo/redo and animate a list view.
If your browser supports WasmGC (such as Chrome 119+, or Firefox 120+), you can try out the app here