[][src]Struct starling::hash_tree::HashTree

pub struct HashTree<ArrayType = [u8; 32], ValueType = Vec<u8>> where
    ValueType: Encode + Decode,
    ArrayType: Array
{ /* fields omitted */ }

A MerkleBIT implemented with a HashMap. Can be used for quickly storing items in memory, though larger sets of items should be stored on disk or over the network in a real database.

Methods

impl<ValueType, ArrayType> HashTree<ArrayType, ValueType> where
    ValueType: Encode + Decode,
    ArrayType: Array
[src]

pub fn new(depth: usize) -> BinaryMerkleTreeResult<Self>[src]

Creates a new HashTree. depth indicates the maximum depth of the tree.

Errors

None.

pub fn open(path: &PathBuf, depth: usize) -> BinaryMerkleTreeResult<Self>[src]

Creates a new HashTree. This method exists for conforming with the general API for the MerkleBIT and does not need to be used (except for compatibility). Prefer new when possible.

Errors

None.

pub fn get(
    &self,
    root_hash: &ArrayType,
    keys: &mut [ArrayType]
) -> BinaryMerkleTreeResult<HashMap<ArrayType, Option<ValueType>>>
[src]

Gets the values associated with keys from the tree.

Errors

Exception generated if the get encounters an invalid state during tree traversal.

pub fn insert(
    &mut self,
    previous_root: Option<&ArrayType>,
    keys: &mut [ArrayType],
    values: &[ValueType]
) -> BinaryMerkleTreeResult<ArrayType>
[src]

Inserts elements into the tree. Using previous_root specifies that the insert depends on the state from the previous root, and will update references accordingly.

Errors

Exception generated if the insert encounters an invalid state during tree traversal.

pub fn remove(&mut self, root_hash: &ArrayType) -> BinaryMerkleTreeResult<()>[src]

Removes a root from the tree. This will remove all elements with less than two references under the given root.

Errors

Exception generated if the remove encounters an invalid state during tree traversal.

pub fn generate_inclusion_proof(
    &self,
    root: &ArrayType,
    key: ArrayType
) -> BinaryMerkleTreeResult<Vec<(ArrayType, bool)>>
[src]

Generates an inclusion proof for the given key at the specified root.

Errors

Exception generated if an invalid state is encountered during tree traversal

pub fn verify_inclusion_proof(
    root: &ArrayType,
    key: ArrayType,
    value: &ValueType,
    proof: &[(ArrayType, bool)]
) -> BinaryMerkleTreeResult<()>
[src]

Verifies an inclusion proof with the given root, key, and value.

Errors

Exception generated if the given proof is invalid.

pub fn get_one(
    &self,
    root: &ArrayType,
    key: &ArrayType
) -> BinaryMerkleTreeResult<Option<ValueType>>
[src]

Gets a single item out of the tree.

Errors

Exception generated if the get_one encounters an invalid state during tree traversal.

pub fn insert_one(
    &mut self,
    previous_root: Option<&ArrayType>,
    key: &ArrayType,
    value: &ValueType
) -> BinaryMerkleTreeResult<ArrayType>
[src]

Inserts a single item into the tree.

Errors

Exception generated if the insert_one encounters an invalid state during tree traversal.

Auto Trait Implementations

impl<ArrayType, ValueType> RefUnwindSafe for HashTree<ArrayType, ValueType> where
    ArrayType: RefUnwindSafe,
    ValueType: RefUnwindSafe

impl<ArrayType, ValueType> Send for HashTree<ArrayType, ValueType> where
    ArrayType: Send,
    ValueType: Send

impl<ArrayType, ValueType> Sync for HashTree<ArrayType, ValueType> where
    ArrayType: Sync,
    ValueType: Sync

impl<ArrayType, ValueType> Unpin for HashTree<ArrayType, ValueType> where
    ArrayType: Unpin,
    ValueType: Unpin

impl<ArrayType, ValueType> UnwindSafe for HashTree<ArrayType, ValueType> where
    ArrayType: UnwindSafe,
    ValueType: UnwindSafe

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.