flat_tree v0.1.2
flat_tree
Map a binary tree to a vector. Port of mafintosh/flat-tree
Installation
-
Add the dependency to your
shard.yml
:dependencies: flat_tree: github: dukeraphaelng/flat_tree
-
Run
shards install
Usage
You can represent a binary tree in a simple flat list using the following structure
3
1 5
0 2 4 6 ...
This module exposes a series of functions to help you build and maintain this data structure
require "flat_tree"
list = [] of String
i = FlatTree.index(0_u64, 0_u64) # get array index for depth: 0, offset: 0
j = FlatTree.index(1_u64, 0_u64) # get array index for depth: 1, offset: 0
# use these indexes to store some data
list[i] = 'a'
list[j] = 'b'
list[FlatTree.parent(i)] = 'parent of a and b'
Contributing
- Fork it (https://github.com/dukeraphaelng/flat_tree/fork)
- Create your feature branch (
git checkout -b my-new-feature
) - Commit your changes (
git commit -am 'Add some feature'
)
- This repository follows Conventional Commits
- Push to the branch (
git push origin my-new-feature
) - Create a new Pull Request
Contributors
- Duke Nguyen - creator and maintainer
License
Repository
flat_tree
Owner
Statistic
- 5
- 0
- 0
- 0
- 0
- about 1 year ago
- April 7, 2021
License
MIT License
Links
Synced at
Thu, 07 Nov 2024 21:57:39 GMT
Languages