[−][src]Struct exonum_merkledb::indexes::proof_map::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: ?Sized, V, KeyMode> ProofMapIndex<T, K, V, KeyMode> where
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
[src]
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
pub fn get(&self, key: &K) -> Option<V>
[src]
Returns a value corresponding to the key.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let mut index = fork.get_proof_map("name"); 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::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let mut index = fork.get_proof_map("name"); let hash = Hash::default(); assert!(!index.contains(&hash)); index.put(&hash, 2); assert!(index.contains(&hash));
pub fn get_proof(&self, key: K::Owned) -> MapProof<K::Owned, V, KeyMode>
[src]
Returns the proof of existence or non-existence for the specified key.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); let proof = index.get_proof(Hash::default());
pub fn get_multiproof<KI>(&self, keys: KI) -> MapProof<K::Owned, V, KeyMode> where
KI: IntoIterator<Item = K::Owned>,
[src]
KI: IntoIterator<Item = K::Owned>,
Returns the combined proof of existence or non-existence for the multiple specified keys.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, String, u8>("name"); let proof = index.get_multiproof(vec!["foo".to_owned(), "bar".to_owned()]);
pub fn iter(&self) -> Entries<K, V>
[src]
Returns an iterator over the entries of the map in ascending order.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); for val in index.iter() { println!("{:?}", val); }
pub fn keys(&self) -> Keys<K>
[src]
Returns an iterator over the keys of the map in ascending order.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); for key in index.keys() { println!("{:?}", key); }
pub fn values(&self) -> Values<V>
[src]
Returns an iterator over the values of the map in ascending order of keys.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); for val in index.values() { println!("{}", val); }
pub fn iter_from(&self, from: &K) -> Entries<K, V>
[src]
Returns an iterator over the entries of the map in ascending order starting from the specified key.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); let hash = Hash::default(); for val in index.iter_from(&hash) { println!("{:?}", val); }
pub fn keys_from(&self, from: &K) -> Keys<K>
[src]
Returns an iterator over the keys of the map in ascending order starting from the specified key.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); let hash = Hash::default(); for key in index.keys_from(&hash) { println!("{:?}", key); }
pub fn values_from(&self, from: &K) -> Values<V>
[src]
Returns an iterator over the values of the map in ascending order of keys starting from the specified key.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let index = fork.get_proof_map::<_, Hash, u8>("name"); let hash = Hash::default(); for val in index.values_from(&hash) { println!("{}", val); }
impl<T, K: ?Sized, V, KeyMode> ProofMapIndex<T, K, V, KeyMode> where
T: RawAccessMut,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
[src]
T: RawAccessMut,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
pub fn put(&mut self, key: &K, value: V)
[src]
Inserts the key-value pair into the proof map.
Examples
use exonum_merkledb::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let mut index = fork.get_proof_map("name"); 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::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let mut index = fork.get_proof_map("name"); 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::{access::CopyAccessExt, TemporaryDB, Database, ProofMapIndex}; use exonum_crypto::Hash; let db = TemporaryDB::new(); let fork = db.fork(); let mut index = fork.get_proof_map("name"); let hash = Hash::default(); index.put(&hash, 2); assert!(index.contains(&hash)); index.clear(); assert!(!index.contains(&hash));
Trait Implementations
impl<T, K: ?Sized, V, KeyMode> Debug for ProofMapIndex<T, K, V, KeyMode> where
T: RawAccess,
K: BinaryKey,
V: BinaryValue + Debug,
KeyMode: ToProofPath<K>,
[src]
T: RawAccess,
K: BinaryKey,
V: BinaryValue + Debug,
KeyMode: ToProofPath<K>,
impl<T, K: ?Sized, V, KeyMode> FromAccess<T> for ProofMapIndex<T::Base, K, V, KeyMode> where
T: Access,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
[src]
T: Access,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
fn from_access(access: T, addr: IndexAddress) -> Result<Self, AccessError>
[src]
fn from_root(access: T) -> Result<Self, AccessError>
[src]
impl<T, K: ?Sized, V, KeyMode> IndexIterator for ProofMapIndex<T, K, V, KeyMode> where
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
[src]
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
type Key = K
Type encompassing index keys.
type Value = V
Type encompassing index values.
fn index_iter(&self, from: Option<&K>) -> Entries<K, V>
[src]
impl<'a, T, K: ?Sized, V, KeyMode> IntoIterator for &'a ProofMapIndex<T, K, V, KeyMode> where
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
[src]
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
type Item = (K::Owned, V)
The type of the elements being iterated over.
type IntoIter = Entries<'a, K, V>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T, K: ?Sized, V, KeyMode> ObjectHash for ProofMapIndex<T, K, V, KeyMode> where
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
[src]
T: RawAccess,
K: BinaryKey,
V: BinaryValue,
KeyMode: ToProofPath<K>,
object_hash()
of a proof map is uniquely determined by its contents (i.e.,
keys and corresponding values). It does not depend on the order of key insertion.
Specification
The object_hash
is defined as
h = sha256( HashTag::MapNode || root_hash )
where root_hash
is computed according to one of the three cases as follows.
Empty map
root_hash = Hash::zero().
Map with a single entry
root_hash = sha256( HashTag::MapBranchNode || path || child_hash ).
Here, the map contains a single path
, and child_hash
is the hash
of the object under this key. path
is serialized as
LEB128(bit_length) || bytes,
where
- LEB128 is a compact serialization format for unsigned integers
bit_length
is the number of bits in the pathbytes
is the path serialized as the minimum necessary number of bytes, with zero padding at the end if necessary.
Map with multiple entries
root_hash = sha256(
HashTag::MapBranchNode
|| left_path || right_path
|| left_hash || right_hash
).
Here, the root node in the Merkle Patricia tree corresponding to the map has left_path
/
right_path
as child paths, and left_hash
/ right_hash
are hashes of child nodes.
These hashes are defined according to the same formula for branch nodes, and for leaves as
leaf_hash = sha256( HashTag::Blob || serialized_value ).
ProofPath
s are serialized in the same way as in the previous case.
Examples
let db = TemporaryDB::new(); let fork = db.fork(); let mut index = fork.get_proof_map("name"); 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);
fn object_hash(&self) -> Hash
[src]
Auto Trait Implementations
impl<T, K: ?Sized, V, KeyMode> RefUnwindSafe for ProofMapIndex<T, K, V, KeyMode> where
K: RefUnwindSafe,
KeyMode: RefUnwindSafe,
T: RefUnwindSafe,
V: RefUnwindSafe,
<T as RawAccess>::Changes: RefUnwindSafe,
K: RefUnwindSafe,
KeyMode: RefUnwindSafe,
T: RefUnwindSafe,
V: RefUnwindSafe,
<T as RawAccess>::Changes: RefUnwindSafe,
impl<T, K: ?Sized, V, KeyMode> Send for ProofMapIndex<T, K, V, KeyMode> where
K: Send,
KeyMode: Send,
T: Send,
V: Send,
<T as RawAccess>::Changes: Send,
K: Send,
KeyMode: Send,
T: Send,
V: Send,
<T as RawAccess>::Changes: Send,
impl<T, K: ?Sized, V, KeyMode> Sync for ProofMapIndex<T, K, V, KeyMode> where
K: Sync,
KeyMode: Sync,
T: Sync,
V: Sync,
<T as RawAccess>::Changes: Sync,
K: Sync,
KeyMode: Sync,
T: Sync,
V: Sync,
<T as RawAccess>::Changes: Sync,
impl<T, K: ?Sized, V, KeyMode> Unpin for ProofMapIndex<T, K, V, KeyMode> where
K: Unpin,
KeyMode: Unpin,
T: Unpin,
V: Unpin,
<T as RawAccess>::Changes: Unpin,
K: Unpin,
KeyMode: Unpin,
T: Unpin,
V: Unpin,
<T as RawAccess>::Changes: Unpin,
impl<T, K: ?Sized, V, KeyMode> UnwindSafe for ProofMapIndex<T, K, V, KeyMode> where
K: UnwindSafe,
KeyMode: UnwindSafe,
T: UnwindSafe,
V: UnwindSafe,
<T as RawAccess>::Changes: UnwindSafe,
K: UnwindSafe,
KeyMode: UnwindSafe,
T: UnwindSafe,
V: UnwindSafe,
<T as RawAccess>::Changes: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
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<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,