#database #immutable #persistent #tree

banyan

Persistent indexable tree data structure

17 releases (7 breaking)

new 0.8.1 Feb 25, 2021
0.7.2 Feb 22, 2021
0.3.0 Sep 15, 2020

#195 in Data structures

Download history 378/week @ 2020-11-10 42/week @ 2020-11-17 7/week @ 2020-11-24 48/week @ 2020-12-01 67/week @ 2020-12-08 75/week @ 2020-12-15 15/week @ 2020-12-29 3/week @ 2021-01-05 9/week @ 2021-01-12 38/week @ 2021-01-19 64/week @ 2021-01-26 59/week @ 2021-02-02 109/week @ 2021-02-09 221/week @ 2021-02-16 130/week @ 2021-02-23

259 downloads per month

MIT/Apache

125KB
2.5K SLoC

Banyan   Build Status Latest Version Docs Badge

banyan tree

Banyan trees are the trees with the widest canopy. They also sprout new roots, which after some time can become indistinguishable from the original root. Seems appropriate.

License

Apache2 or MIT

Design goals

  • fat leafs, containing as much data as possible and being roughly the same size
  • low depth, fat branches
  • quick traversal, filtering and random access
  • cheap append (possible, but would require more complex interaction with block store)
  • no insert/splice
  • possibility for removal

Tree structure

The tree should have a structure that is fully determined by the content, unlike e.g. a balanced tree which has a memory of its history.

It should support append and bulk append.

Node structure

A node is split into two parts. An index part that lives in the parent for quick access, and a value part that is linked from the parent.

Leaf builder

Leafs are the biggest things. The builder incrementally encodes and compresses data. The state of a builder should at any time be able to be persisted. The storage format should be also incremental (adding stuff at the end does not require changes at the start)

Branch builder

Whereas leafs are always appended to, branches are most of the time updated at their last index. Branches are stored as valid IPLD so they can be traversed by ipfs. The non-link data is zstd compressed cbor.

Dependencies

~11MB
~248K SLoC