2020-05-16 16:15:47 +00:00
|
|
|
# flat-tree
|
2019-06-20 15:12:38 +00:00
|
|
|
|
2020-05-16 16:15:47 +00:00
|
|
|
[![Build Status](https://drone.autonomic.zone/api/badges/hyperpy/flat-tree/status.svg)](https://drone.autonomic.zone/hyperpy/flat-tree)
|
2019-06-20 15:12:38 +00:00
|
|
|
|
2020-05-16 16:15:47 +00:00
|
|
|
## Utilities for navigating flat trees
|
2019-06-20 15:12:38 +00:00
|
|
|
|
2020-05-16 16:18:31 +00:00
|
|
|
> Flat Trees are the core data structure that power Hypercore feeds. They allow
|
|
|
|
> us to deterministically represent a tree structure as a vector. This is
|
|
|
|
> particularly useful because vectors map elegantly to disk and memory. Because
|
|
|
|
> Flat Trees are deterministic and pre-computed, there is no overhead to using
|
|
|
|
> them. In effect this means that Flat Trees are a specific way of indexing
|
|
|
|
> into a vector more than they are their own data structure. This makes them
|
|
|
|
> uniquely efficient and convenient to implement in a wide range of languages.
|
2020-07-07 13:04:50 +00:00
|
|
|
|
|
|
|
## Install
|
|
|
|
|
2020-07-07 13:08:43 +00:00
|
|
|
```sh
|
2020-07-07 13:04:50 +00:00
|
|
|
$ pip install flat-tree
|
|
|
|
```
|
|
|
|
|
|
|
|
## Example
|
|
|
|
|
2020-07-07 13:08:43 +00:00
|
|
|
```python
|
2020-08-05 06:19:41 +00:00
|
|
|
from flat_tree import FlatTreeIterator
|
2020-07-07 13:08:43 +00:00
|
|
|
|
|
|
|
tree_iter = FlatTreeIterator()
|
2020-08-05 06:19:41 +00:00
|
|
|
|
|
|
|
print("tree index: ", tree_iter.index)
|
|
|
|
print("tree first parent: ", tree_iter.parent())
|
|
|
|
print("tree next parent", tree_iter.parent())
|
|
|
|
```
|
|
|
|
|
|
|
|
Output:
|
|
|
|
|
|
|
|
```sh
|
|
|
|
tree index: 0
|
|
|
|
tree first parent: 1
|
|
|
|
tree next parent 3
|
2020-07-07 13:04:50 +00:00
|
|
|
```
|