Red/black tree with support for fast accumulation of values in a key range
Switch branches/tags
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.circleci
accumulation_tree
MANIFEST
Makefile
README.md
setup.py
tests.md

README.md

accumulation_tree

CircleCI

A red/black tree which also stores partial aggregations at each node, making getting aggregations of key range slices an O(log(N)) operation.

This implementation was written specifically for use in tdigest, and borrows code from bintrees.

Synopsis

>>> from accumulation_tree import AccumulationTree
>>> t = AccumulationTree(lambda x: x)
>>> N = 10000
>>> for x in range(N):
...    t.insert(x,x)
>>> t.get_accumulation(0, 2)
1
>>> t.get_accumulation(0, 5)
10
>>> all(t.get_accumulation(0, x) == x*(x-1)/2 for x in range(N))
True