[−][src]Struct exonum_merkledb::proof_map_index::ProofMapIndex
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 values as leaves.
ProofMapIndex
requires that keys implement the BinaryKey
trait and
values implement the BinaryValue
trait.
Methods
impl<T, K, V> ProofMapIndex<T, K, V> where
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
[src]
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
pub fn new<S: Into<String>>(index_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_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let snapshot = db.snapshot(); let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &snapshot); let fork = db.fork(); let mut mut_index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new(name, &fork);
pub fn new_in_family<S, I>(family_name: S, index_id: &I, view: T) -> Self where
I: BinaryKey,
I: ?Sized,
S: Into<String>,
[src]
I: BinaryKey,
I: ?Sized,
S: Into<String>,
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, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let index_id = vec![01]; let snapshot = db.snapshot(); let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new_in_family( name, &index_id, &snapshot, ); let fork = db.fork(); let mut mut_index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new_in_family( name, &index_id, &fork, );
pub fn get(&self, key: &K) -> Option<V>
[src]
Returns a value corresponding to the key.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let fork = db.fork(); let mut index = ProofMapIndex::new(name, &fork); let hash = Hash::default(); assert_eq!(None, index.get(&hash)); index.put(&hash, 2); assert_eq!(Some(2), index.get(&hash));
pub fn contains(&self, key: &K) -> bool
[src]
Returns true
if the map contains a value for the specified key.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let fork = db.fork(); let mut index = ProofMapIndex::new(name, &fork); let hash = Hash::default(); assert!(!index.contains(&hash)); index.put(&hash, 2); assert!(index.contains(&hash));
pub fn get_proof(&self, key: K) -> MapProof<K, V>
[src]
Returns the proof of existence or non-existence for the specified key.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let snapshot = db.snapshot(); let index: ProofMapIndex<_, Hash, u8> = ProofMapIndex::new("index", &snapshot); let proof = index.get_proof(Hash::default());
pub fn get_multiproof<KI>(&self, keys: KI) -> MapProof<K, V> where
KI: IntoIterator<Item = K>,
[src]
KI: IntoIterator<Item = K>,
Returns the combined proof of existence or non-existence for the multiple specified keys.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; let db = TemporaryDB::new(); let snapshot = db.snapshot(); let index: ProofMapIndex<_, Vec<u8>, u8> = ProofMapIndex::new("index", &snapshot); let proof = index.get_multiproof(vec![vec![0; 32], vec![1; 32]]);
ⓘImportant traits for ProofMapIndexIter<'a, K, V>pub 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::Output, V)
.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::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>pub fn keys(&self) -> ProofMapIndexKeys<K>
[src]
Returns an iterator over the keys of the map in ascending order. The iterator element
type is K::Output
.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::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>pub 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_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::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>pub 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::Output, V)
.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::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>pub 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::Output
.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::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>pub 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_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::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); }
pub fn put(&mut self, key: &K, value: V)
[src]
Inserts the key-value pair into the proof map.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let fork = db.fork(); let mut index = ProofMapIndex::new(name, &fork); let hash = Hash::default(); index.put(&hash, 2); assert!(index.contains(&hash));
pub fn remove(&mut self, key: &K)
[src]
Removes a key from the proof map.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let fork = db.fork(); let mut index = ProofMapIndex::new(name, &fork); let hash = Hash::default(); index.put(&hash, 2); assert!(index.contains(&hash)); index.remove(&hash); assert!(!index.contains(&hash));
pub fn clear(&mut self)
[src]
Clears the proof map, removing all entries.
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, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let fork = db.fork(); let mut index = ProofMapIndex::new(name, &fork); let hash = Hash::default(); index.put(&hash, 2); assert!(index.contains(&hash)); index.clear(); assert!(!index.contains(&hash));
Trait Implementations
impl<T, K, V> ObjectHash for ProofMapIndex<T, K, V> where
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
[src]
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
fn object_hash(&self) -> Hash
[src]
Returns the hash of the proof map object. See HashTag::hash_map_node
.
For hash of the empty map see HashTag::empty_map_hash
.
Examples
use exonum_merkledb::{TemporaryDB, Database, ProofMapIndex, HashTag, ObjectHash}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let name = "name"; let fork = db.fork(); let mut index = ProofMapIndex::new(name, &fork); let default_hash = index.object_hash(); assert_eq!(HashTag::empty_map_hash(), default_hash); index.put(&default_hash, 100); let hash = index.object_hash(); assert_ne!(hash, default_hash);
impl<'a, T, K, V> IntoIterator for &'a ProofMapIndex<T, K, V> where
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
[src]
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash,
type Item = (K::Owned, V)
The type of the elements being iterated over.
type IntoIter = ProofMapIndexIter<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T, K, V> Debug for ProofMapIndex<T, K, V> where
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash + Debug,
[src]
T: IndexAccess,
K: BinaryKey + ObjectHash,
V: BinaryValue + ObjectHash + Debug,
Auto Trait Implementations
impl<T, K, V> !Sync for ProofMapIndex<T, K, V>
impl<T, K, V> Send for ProofMapIndex<T, K, V> where
K: Send,
T: Send,
V: Send,
<T as IndexAccess>::Changes: Send,
K: Send,
T: Send,
V: Send,
<T as IndexAccess>::Changes: Send,
impl<T, K, V> Unpin for ProofMapIndex<T, K, V> where
K: Unpin,
T: Unpin,
V: Unpin,
<T as IndexAccess>::Changes: Unpin,
K: Unpin,
T: Unpin,
V: Unpin,
<T as IndexAccess>::Changes: Unpin,
impl<T, K, V> !RefUnwindSafe for ProofMapIndex<T, K, V>
impl<T, K, V> UnwindSafe for ProofMapIndex<T, K, V> where
K: UnwindSafe,
T: UnwindSafe,
V: UnwindSafe,
<T as IndexAccess>::Changes: UnwindSafe,
K: UnwindSafe,
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]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,