Struct exonum::storage::proof_map_index::ProofMapIndex [] [src]

pub struct ProofMapIndex<T, K, V> { /* fields omitted */ }

A Merkelized version of a map that provides proofs of existence or non-existence for the map keys.

ProofMapIndex implements a Merkle Patricia tree, storing the values as leaves. ProofMapIndex requires that the keys implement ProofMapKey and values implement the StorageValue trait.

The size of the proof map keys must be exactly 32 bytes and the keys must have a uniform distribution. Usually Hash and PublicKey are used as types of proof map keys.

Methods

impl<T, K, V> ProofMapIndex<T, K, V> where
    T: AsRef<Snapshot>,
    K: ProofMapKey,
    V: StorageValue
[src]

[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::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

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

[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::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let prefix = vec![01];

let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> =
                            ProofMapIndex::with_prefix(name, prefix.clone(), &snapshot);

let mut fork = db.fork();
let mut mut_index : ProofMapIndex<_, Hash, u8> =
                                    ProofMapIndex::with_prefix(name, prefix, &mut fork);

[src]

Returns the root hash of the proof map or default hash value if it is empty.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

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

let default_hash = index.root_hash();
assert_eq!(Hash::default(), default_hash);

index.put(&default_hash, 100);
let hash = index.root_hash();
assert_ne!(hash, default_hash);

[src]

Returns a value corresponding to the key.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

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

let hash = Hash::default();
assert_eq!(None, index.get(&hash));

index.put(&hash, 2);
assert_eq!(Some(2), index.get(&hash));

[src]

Returns true if the map contains a value for the specified key.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

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

let hash = Hash::default();
assert!(!index.contains(&hash));

index.put(&hash, 2);
assert!(index.contains(&hash));

[src]

Returns the proof of existence or non-existence for the specified key.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

let hash = Hash::default();
let proof = index.get_proof(&hash);

Important traits for ProofMapIndexIter<'a, K, V>
[src]

Returns an iterator over the entries of the map in ascending order. The iterator element type is (K, V).

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

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

Important traits for ProofMapIndexKeys<'a, K>
[src]

Returns an iterator over the keys of the map in ascending order. The iterator element type is K.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

for key in index.keys() {
    println!("{:?}", key);
}

Important traits for ProofMapIndexValues<'a, V>
[src]

Returns an iterator over the values of the map in ascending order of keys. The iterator element type is V.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

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

Important traits for ProofMapIndexIter<'a, K, V>
[src]

Returns an iterator over the entries of the map in ascending order starting from the specified key. The iterator element type is (K, V).

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

let hash = Hash::default();
for val in index.iter_from(&hash) {
    println!("{:?}", val);
}

Important traits for ProofMapIndexKeys<'a, K>
[src]

Returns an iterator over the keys of the map in ascending order starting from the specified key. The iterator element type is K.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

let hash = Hash::default();
for key in index.keys_from(&hash) {
    println!("{:?}", key);
}

Important traits for ProofMapIndexValues<'a, V>
[src]

Returns an iterator over the values of the map in ascending order of keys starting from the specified key. The iterator element type is V.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot);

let hash = Hash::default();
for val in index.values_from(&hash) {
    println!("{}", val);
}

impl<'a, K, V> ProofMapIndex<&'a mut Fork, K, V> where
    K: ProofMapKey,
    V: StorageValue
[src]

[src]

Inserts the key-value pair into the proof map.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

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

let hash = Hash::default();
index.put(&hash, 2);
assert!(index.contains(&hash));

[src]

Removes the key from the proof map.

Examples

use exonum::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

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

let hash = Hash::default();
index.put(&hash, 2);
assert!(index.contains(&hash));

index.remove(&hash);
assert!(!index.contains(&hash));

[src]

Clears the proof map, removing all entries.

Notes

Currently this method is not optimized to delete 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::storage::{MemoryDB, Database, ProofMapIndex};
use exonum::crypto::Hash;

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

let hash = Hash::default();
index.put(&hash, 2);
assert!(index.contains(&hash));

index.clear();
assert!(!index.contains(&hash));

Trait Implementations

impl<'a, T, K, V> IntoIterator for &'a ProofMapIndex<T, K, V> where
    T: AsRef<Snapshot>,
    K: ProofMapKey,
    V: StorageValue
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more

impl<T, K, V> Debug for ProofMapIndex<T, K, V> where
    T: AsRef<Snapshot>,
    K: ProofMapKey,
    V: StorageValue + Debug
[src]

[src]

Formats the value using the given formatter. Read more

Auto Trait Implementations

impl<T, K, V> Send for ProofMapIndex<T, K, V> where
    K: Send,
    T: Send,
    V: Send

impl<T, K, V> Sync for ProofMapIndex<T, K, V> where
    K: Sync,
    T: Sync,
    V: Sync