Struct exonum::storage::proof_map_index::ProofMapIndex
[−]
[src]
pub struct ProofMapIndex<T, K, V> { /* fields omitted */ }
A Merkalized 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>
[src]
fn new<S: AsRef<str>>(name: S, view: 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::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);
fn with_prefix<S: AsRef<str>>(name: S, prefix: Vec<u8>, view: T) -> Self
[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);
impl<T, K, V> ProofMapIndex<T, K, V> where
T: AsRef<Snapshot>,
K: ProofMapKey,
V: StorageValue,
[src]
T: AsRef<Snapshot>,
K: ProofMapKey,
V: StorageValue,
fn root_hash(&self) -> Hash
[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);
fn get(&self, key: &K) -> Option<V>
[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));
fn contains(&self, key: &K) -> bool
[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));
fn get_proof(&self, key: &K) -> MapProof<V>
[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);
fn iter(&self) -> ProofMapIndexIter<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); }
fn keys(&self) -> ProofMapIndexKeys<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); }
fn values(&self) -> ProofMapIndexValues<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); }
fn iter_from(&self, from: &K) -> ProofMapIndexIter<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); }
fn keys_from(&self, from: &K) -> ProofMapIndexKeys<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); }
fn values_from(&self, from: &K) -> ProofMapIndexValues<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]
K: ProofMapKey,
V: StorageValue,
fn put(&mut self, key: &K, value: V)
[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));
fn remove(&mut self, key: &K)
[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));
fn clear(&mut self)
[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<T: Debug, K: Debug, V: Debug> Debug for ProofMapIndex<T, K, V>
[src]
impl<'a, T, K, V> IntoIterator for &'a ProofMapIndex<T, K, V> where
T: AsRef<Snapshot>,
K: ProofMapKey,
V: StorageValue,
[src]
T: AsRef<Snapshot>,
K: ProofMapKey,
V: StorageValue,