Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tkluck/accumulation_tree
Red/black tree with support for fast accumulation of values in a key range
https://github.com/tkluck/accumulation_tree
Last synced: 19 days ago
JSON representation
Red/black tree with support for fast accumulation of values in a key range
- Host: GitHub
- URL: https://github.com/tkluck/accumulation_tree
- Owner: tkluck
- License: mit
- Created: 2017-02-05T23:32:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-05-09T18:00:09.000Z (over 4 years ago)
- Last Synced: 2024-05-02T06:13:54.992Z (7 months ago)
- Language: Python
- Size: 23.4 KB
- Stars: 17
- Watchers: 4
- Forks: 2
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
`accumulation_tree`
===================[![CircleCI][circleci-img]][circleci-url]
[circleci-url]: https://circleci.com/gh/tkluck/accumulation_tree/
[circleci-img]: https://img.shields.io/circleci/project/github/tkluck/pac4cli.svgA red/black tree which also stores partial aggregations at each node, making
getting aggregations of key range slices an O(log(N)) operation.This data structure is very similar to a [Fenwick tree][wiki] and can be used
for the same purpose. The main difference with the description on Wikipedia is
that we allocate nodes on the heap instead of using an implicit tree structure
on a flat array.This implementation was written specifically for use in [tdigest][tdigest-github],
and borrows code from [bintrees][bintrees-github].[tdigest-github]: https://github.com/CamDavidsonPilon/tdigest/
[bintrees-github]: https://github.com/mozman/bintrees/
[wiki]: https://en.wikipedia.org/wiki/Fenwick_treeSynopsis
--------
```python
>>> 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```