Struct tree_index::TreeIndex [−][src]
pub struct TreeIndex { /* fields omitted */ }
Index a tree structure or something.
Methods
impl TreeIndex
[src]
impl TreeIndex
pub fn new(bitfield: Bitfield) -> Self
[src]
pub fn new(bitfield: Bitfield) -> Self
Create a new TreeIndex by passing it a sparse_bitfield instance.
pub fn get(&mut self, index: usize) -> bool
[src]
pub fn get(&mut self, index: usize) -> bool
Get a bit from the bitfield.
pub fn set(&mut self, index: usize) -> Change
[src]
pub fn set(&mut self, index: usize) -> Change
Set an index on the tree to true
, and also all of the parents to the
index. Walks the flat-tree upward, until it finds the upper most node.
pub fn proof<'a>(
&'a mut self,
index: usize,
include_hash: bool,
nodes: &'a mut impl AsMut<Vec<usize>>,
remote_tree: &mut Self
) -> Option<Proof>
[src]
pub fn proof<'a>(
&'a mut self,
index: usize,
include_hash: bool,
nodes: &'a mut impl AsMut<Vec<usize>>,
remote_tree: &mut Self
) -> Option<Proof>
Prove a method.
pub fn proof_with_digest<'a>(
&'a mut self,
index: usize,
digest: usize,
include_hash: bool,
nodes: &'a mut impl AsMut<Vec<usize>>,
remote_tree: &mut Self
) -> Option<Proof>
[src]
pub fn proof_with_digest<'a>(
&'a mut self,
index: usize,
digest: usize,
include_hash: bool,
nodes: &'a mut impl AsMut<Vec<usize>>,
remote_tree: &mut Self
) -> Option<Proof>
Determine which Nodes prove the correctness for the Node at index
.
The passed buffer is filled with nodes that are verified by the same index. This is done so allocations can happen at the top level, and a buffer (pool) can be used to prevent extra allocations.
pub fn digest(&mut self, index: usize) -> usize
[src]
pub fn digest(&mut self, index: usize) -> usize
Create a digest for data at index.
pub fn blocks(&mut self) -> usize
[src]
pub fn blocks(&mut self) -> usize
Get the position of the highest entry in the tree. Aka max.
NOTE: should we rename this to .len()
?
Examples
3
1 5
0 2 4 6
extern crate tree_index as tree; use tree::{Change, TreeIndex, Verification}; let mut tree = TreeIndex::default(); for i in (0..8).step_by(2) { tree.set(i); } assert_eq!(tree.blocks(), 4); tree = TreeIndex::default(); tree.set(1); tree.set(5); assert_eq!(tree.blocks(), 4); tree = TreeIndex::default(); tree.set(3); assert_eq!(tree.blocks(), 4);
pub fn roots(&mut self, roots: &mut Vec<usize>)
[src]
pub fn roots(&mut self, roots: &mut Vec<usize>)
Get all root nodes.
TODO: don't make this allocate, but fill a vector instead.
pub fn verified_by(&mut self, index: usize) -> Verification
[src]
pub fn verified_by(&mut self, index: usize) -> Verification
Find the node that verified the node that's passed.
This is different from the Javascript implementation in that it doesn't
push the top
value into an array, but returns it instead through the
Verification
type.
Trait Implementations
impl Debug for TreeIndex
[src]
impl Debug for TreeIndex
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Default for TreeIndex
[src]
impl Default for TreeIndex
Create a TreeIndex with an empty sparse_bitfield instance with a page size
of 1024
.