[][src]Struct tree_index::TreeIndex

pub struct TreeIndex { /* fields omitted */ }

Index a tree structure or something.

Implementations

impl TreeIndex[src]

pub fn new(bitfield: Bitfield) -> Self[src]

Create a new TreeIndex by passing it a sparse_bitfield instance.

pub fn get(&mut self, index: u64) -> bool[src]

Get a bit from the bitfield.

pub fn set(&mut self, index: u64) -> Change[src]

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: u64,
    include_hash: bool,
    nodes: &'a mut impl AsMut<Vec<u64>>,
    remote_tree: &mut Self
) -> Option<Proof>
[src]

Prove a method.

pub fn proof_with_digest<'a>(
    &'a mut self,
    index: u64,
    digest: u64,
    include_hash: bool,
    nodes: &'a mut impl AsMut<Vec<u64>>,
    remote_tree: &mut Self
) -> Option<Proof>
[src]

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: u64) -> u64[src]

Create a digest for data at index.

pub fn blocks(&mut self) -> u64[src]

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<u64>)[src]

Get all root nodes.

TODO: don't make this allocate, but fill a vector instead.

pub fn verified_by(&mut self, index: u64) -> Verification[src]

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.

pub fn as_bitfield(&self) -> &Bitfield[src]

Get a reference to underlying bitfield

Trait Implementations

impl Debug for TreeIndex[src]

impl Default for TreeIndex[src]

Create a TreeIndex with an empty sparse_bitfield instance with a page size of 1024.

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.