[][src]Struct exonum_merkledb::proof_list_index::ProofListIndex

pub struct ProofListIndex<T: IndexAccess, V> { /* fields omitted */ }

A Merkelized version of an array list that provides proofs of existence for the list items.

ProofListIndex implements a Merkle tree, storing elements as leaves and using u64 as an index. ProofListIndex requires that elements implement the BinaryValue trait.

Methods

impl<T, V> ProofListIndex<T, V> where
    T: IndexAccess,
    V: BinaryValue
[src]

pub fn new<S: Into<String>>(index_name: S, index_access: T) -> Self[src]

Creates a new index representation based on the name and storage view.

Storage view can be specified as &Snapshot or &mut Fork. In the first case, only immutable methods are available. In the second case, both immutable and mutable methods are available.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";

let snapshot = db.snapshot();
let index: ProofListIndex<_, u8> = ProofListIndex::new(name, &snapshot);

let fork = db.fork();
let mut mut_index: ProofListIndex<_, u8> = ProofListIndex::new(name, &fork);

pub fn new_in_family<S, I>(
    family_name: S,
    index_id: &I,
    index_access: T
) -> Self where
    I: BinaryKey,
    I: ?Sized,
    S: Into<String>, 
[src]

Creates a new index representation based on the name, common prefix of its keys and storage view.

Storage view can be specified as &Snapshot or &mut Fork. In the first case, only immutable methods are available. In the second case, both immutable and mutable methods are available.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let index_id = vec![01];

let snapshot = db.snapshot();
let index: ProofListIndex<_, u8> =
                            ProofListIndex::new_in_family(name, &index_id, &snapshot);

let fork = db.fork();
let mut mut_index : ProofListIndex<_, u8> =
                                ProofListIndex::new_in_family(name, &index_id, &fork);

pub fn get(&self, index: u64) -> Option<V>[src]

Returns the element at the indicated position or None if the indicated position is out of bounds.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);
assert_eq!(None, index.get(0));

index.push(10);
assert_eq!(Some(10), index.get(0));

pub fn last(&self) -> Option<V>[src]

Returns the last element of the proof list or None if it is empty.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);
assert_eq!(None, index.last());

index.push(1);
assert_eq!(Some(1), index.last());

pub fn is_empty(&self) -> bool[src]

Returns true if the proof list contains no elements.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);
assert!(index.is_empty());

index.push(10);
assert!(!index.is_empty());

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

Returns the number of elements in the proof list.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);
assert_eq!(0, index.len());

index.push(1);
assert_eq!(1, index.len());

pub fn height(&self) -> u8[src]

Returns the height of the proof list.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);
assert_eq!(1, index.height());

index.push(1);
assert_eq!(1, index.len());

index.push(1);
assert_eq!(2, index.len());

pub fn get_proof(&self, index: u64) -> ListProof<V>[src]

Returns a proof of existence for the list element at the specified position.

Returns a proof of absence if the list doesn't contain an element with the specified index.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

index.push(1);

let proof = index.get_proof(0);

let proof_of_absence = index.get_proof(1);

pub fn get_range_proof<R: RangeBounds<u64>>(&self, range: R) -> ListProof<V>[src]

Returns the proof of existence for the list elements in the specified range.

Returns a proof of absence for a range of values, if either or both its bounds exceed the list state.

Panics

Panics if the range bounds are illegal.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

index.extend([1, 2, 3, 4, 5].iter().cloned());

let list_proof = index.get_range_proof(1..3);

// Range (1..10) doesn't exist in index.
let list_proof_of_absence = index.get_range_proof(1..10);

Important traits for ProofListIndexIter<'a, V>
pub fn iter(&self) -> ProofListIndexIter<V>[src]

Returns an iterator over the list. The iterator element type is V.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofListIndex<_, u8> = ProofListIndex::new(name, &snapshot);

for val in index.iter() {
    println!("{}", val);
}

Important traits for ProofListIndexIter<'a, V>
pub fn iter_from(&self, from: u64) -> ProofListIndexIter<V>[src]

Returns an iterator over the list starting from the specified position. The iterator element type is V.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofListIndex<_, u8> = ProofListIndex::new(name, &snapshot);

for val in index.iter_from(1) {
    println!("{}", val);
}

pub fn push(&mut self, value: V)[src]

Appends an element to the back of the proof list.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

index.push(1);
assert!(!index.is_empty());

pub fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = V>, 
[src]

Extends the proof list with the contents of an iterator.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

index.extend([1, 2, 3].iter().cloned());
assert_eq!(3, index.len());

pub fn set(&mut self, index: u64, value: V)[src]

Changes a value at the specified position.

Panics

Panics if index is equal or greater than the current state of the proof list.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

index.push(1);
assert_eq!(Some(1), index.get(0));

index.set(0, 100);
assert_eq!(Some(100), index.get(0));

pub fn clear(&mut self)[src]

Clears the proof list, removing all values.

Notes

Currently, this method is not optimized to delete a large set of data. During the execution of this method, the amount of allocated memory is linearly dependent on the number of elements in the index.

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex};

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

index.push(1);
assert!(!index.is_empty());

index.clear();
assert!(index.is_empty());

Trait Implementations

impl<T, V> ObjectHash for ProofListIndex<T, V> where
    T: IndexAccess,
    V: BinaryValue + ObjectHash
[src]

fn object_hash(&self) -> Hash[src]

Returns a list hash of the proof list or a hash value of the empty list.

List hash is calculated as follows:

h = sha-256( HashTag::List || len as u64 || merkle_root )

Empty list hash:

h = sha-256( HashTag::List || 0 || Hash::default() )

Examples

use exonum_merkledb::{TemporaryDB, Database, ProofListIndex, HashTag, ObjectHash};
use exonum_crypto::Hash;

let db = TemporaryDB::new();
let name = "name";
let fork = db.fork();
let mut index = ProofListIndex::new(name, &fork);

let default_hash = index.object_hash();
assert_eq!(HashTag::empty_list_hash(), default_hash);

index.push(1);
let hash = index.object_hash();
assert_ne!(hash, default_hash);

impl<'a, T, V> IntoIterator for &'a ProofListIndex<T, V> where
    T: IndexAccess,
    V: BinaryValue + ObjectHash
[src]

type Item = V

The type of the elements being iterated over.

type IntoIter = ProofListIndexIter<'a, V>

Which kind of iterator are we turning this into?

impl<T: Debug + IndexAccess, V: Debug> Debug for ProofListIndex<T, V>[src]

Auto Trait Implementations

impl<T, V> !Sync for ProofListIndex<T, V>

impl<T, V> Send for ProofListIndex<T, V> where
    T: Send,
    V: Send,
    <T as IndexAccess>::Changes: Send

impl<T, V> Unpin for ProofListIndex<T, V> where
    T: Unpin,
    V: Unpin,
    <T as IndexAccess>::Changes: Unpin

impl<T, V> !RefUnwindSafe for ProofListIndex<T, V>

impl<T, V> UnwindSafe for ProofListIndex<T, V> where
    T: UnwindSafe,
    V: UnwindSafe,
    <T as IndexAccess>::Changes: UnwindSafe

Blanket Implementations

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.

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

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

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

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,