referrerpolicy=no-referrer-when-downgrade
sp_state_machine

Type Alias MemoryDB

pub type MemoryDB<H> = MemoryDB<H, HashKey<H>, Vec<u8>>;
Expand description

Reexport from hash_db, with genericity set for Hasher trait. This uses a noops KeyFunction (key addressing must be hashed or using an encoding scheme that avoid key conflict).

Aliased Type§

struct MemoryDB<H> { /* private fields */ }

Implementations

§

impl<H, KF, T> MemoryDB<H, KF, T>
where H: Hasher, T: Default, KF: KeyFunction<H>,

Create a new MemoryDB from a given null key/data

pub fn remove_and_purge( &mut self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>), ) -> Option<T>

Remove an element and delete it from storage if reference count reaches zero. If the value was purged, return the old value.

pub fn shrink_to_fit(&mut self)

Shrinks the capacity of the map as much as possible. It will drop down as much as possible while maintaining the internal rules and possibly leaving some space in accordance with the resize policy.

§

impl<H, KF, T> MemoryDB<H, KF, T>
where H: Hasher, T: for<'a> From<&'a [u8]>, KF: KeyFunction<H>,

pub fn from_null_node(null_key: &[u8], null_node_data: T) -> MemoryDB<H, KF, T>

Create a new MemoryDB from a given null key/data

pub fn new(data: &[u8]) -> MemoryDB<H, KF, T>

Create a new instance of Self.

pub fn default_with_root() -> (MemoryDB<H, KF, T>, <H as Hasher>::Out)

Create a new default instance of Self and returns Self and the root hash.

pub fn clear(&mut self)

Clear all data from the database.

§Examples
extern crate hash_db;
extern crate keccak_hasher;
extern crate memory_db;

use hash_db::{Hasher, HashDB, EMPTY_PREFIX};
use keccak_hasher::KeccakHasher;
use memory_db::{MemoryDB, HashKey};

fn main() {
  let mut m = MemoryDB::<KeccakHasher, HashKey<_>, Vec<u8>>::default();
  let hello_bytes = "Hello world!".as_bytes();
  let hash = m.insert(EMPTY_PREFIX, hello_bytes);
  assert!(m.contains(&hash, EMPTY_PREFIX));
  m.clear();
  assert!(!m.contains(&hash, EMPTY_PREFIX));
}

pub fn purge(&mut self)

Purge all zero-referenced data from the database.

pub fn drain(&mut self) -> HashMap<<KF as KeyFunction<H>>::Key, (T, i32)>

Return the internal key-value Map, clearing the current state.

pub fn raw( &self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>), ) -> Option<(&T, i32)>

Grab the raw information associated with a key. Returns None if the key doesn’t exist.

Even when Some is returned, the data is only guaranteed to be useful when the refs > 0.

pub fn consolidate(&mut self, other: MemoryDB<H, KF, T>)

Consolidate all the entries of other into self.

pub fn keys(&self) -> HashMap<<KF as KeyFunction<H>>::Key, i32>

Get the keys in the database together with number of underlying references.

Trait Implementations

§

impl<H, KF, T> AsHashDB<H, T> for MemoryDB<H, KF, T>
where H: Hasher, T: Default + PartialEq + AsRef<[u8]> + for<'a> From<&'a [u8]> + Clone + Send + Sync, KF: KeyFunction<H> + Send + Sync,

§

fn as_hash_db(&self) -> &dyn HashDB<H, T>

Perform upcast to HashDB for anything that derives from HashDB.
§

fn as_hash_db_mut(&mut self) -> &mut dyn HashDB<H, T>

Perform mutable upcast to HashDB for anything that derives from HashDB.
§

impl<H, KF, T> AsPlainDB<<H as Hasher>::Out, T> for MemoryDB<H, KF, T>
where H: Hasher, T: Default + PartialEq + for<'a> From<&'a [u8]> + Clone + Send + Sync, KF: KeyFunction<H> + Send + Sync, <KF as KeyFunction<H>>::Key: Borrow<[u8]> + for<'a> From<&'a [u8]>,

§

fn as_plain_db(&self) -> &dyn PlainDB<<H as Hasher>::Out, T>

Perform upcast to PlainDB for anything that derives from PlainDB.
§

fn as_plain_db_mut(&mut self) -> &mut dyn PlainDB<<H as Hasher>::Out, T>

Perform mutable upcast to PlainDB for anything that derives from PlainDB.
§

impl<H, KF, T> Clone for MemoryDB<H, KF, T>
where H: Hasher, KF: KeyFunction<H>, T: Clone,

§

fn clone(&self) -> MemoryDB<H, KF, T>

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl<H, KF, T> Default for MemoryDB<H, KF, T>
where H: Hasher, T: for<'a> From<&'a [u8]>, KF: KeyFunction<H>,

§

fn default() -> MemoryDB<H, KF, T>

Returns the “default value” for a type. Read more
§

impl<H> From<&StorageProof> for MemoryDB<H, HashKey<H>, Vec<u8>>
where H: Hasher,

§

fn from(proof: &StorageProof) -> MemoryDB<H, HashKey<H>, Vec<u8>>

Converts to this type from the input type.
§

impl<H> From<StorageProof> for MemoryDB<H, HashKey<H>, Vec<u8>>
where H: Hasher,

§

fn from(proof: StorageProof) -> MemoryDB<H, HashKey<H>, Vec<u8>>

Converts to this type from the input type.
§

impl<H, KF, T> HashDB<H, T> for MemoryDB<H, KF, T>
where H: Hasher, T: Default + PartialEq + AsRef<[u8]> + for<'a> From<&'a [u8]> + Clone + Send + Sync, KF: KeyFunction<H> + Send + Sync,

§

fn get( &self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>), ) -> Option<T>

Look up a given hash into the bytes that hash to it, returning None if the hash is not known.
§

fn contains( &self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>), ) -> bool

Check for the existence of a hash-key.
§

fn emplace( &mut self, key: <H as Hasher>::Out, prefix: (&[u8], Option<u8>), value: T, )

Like insert(), except you provide the key and the data is all moved.
§

fn insert( &mut self, prefix: (&[u8], Option<u8>), value: &[u8], ) -> <H as Hasher>::Out

Insert a datum item into the DB and return the datum’s hash for a later lookup. Insertions are counted and the equivalent number of remove()s must be performed before the data is considered dead.
§

fn remove(&mut self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>))

Remove a datum previously inserted. Insertions can be “owed” such that the same number of insert()s may happen without the data being eventually being inserted into the DB. It can be “owed” more than once.
§

impl<H, KF, T> HashDBRef<H, T> for MemoryDB<H, KF, T>
where H: Hasher, T: Default + PartialEq + AsRef<[u8]> + for<'a> From<&'a [u8]> + Clone + Send + Sync, KF: KeyFunction<H> + Send + Sync,

§

fn get( &self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>), ) -> Option<T>

Look up a given hash into the bytes that hash to it, returning None if the hash is not known.
§

fn contains( &self, key: &<H as Hasher>::Out, prefix: (&[u8], Option<u8>), ) -> bool

Check for the existance of a hash-key.
§

impl<H, KF, T> PartialEq for MemoryDB<H, KF, T>
where H: Hasher, KF: KeyFunction<H>, T: Eq + MaybeDebug,

§

fn eq(&self, other: &MemoryDB<H, KF, T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
§

impl<H, KF, T> PlainDB<<H as Hasher>::Out, T> for MemoryDB<H, KF, T>
where H: Hasher, T: Default + PartialEq + for<'a> From<&'a [u8]> + Clone + Send + Sync, KF: Send + Sync + KeyFunction<H>, <KF as KeyFunction<H>>::Key: Borrow<[u8]> + for<'a> From<&'a [u8]>,

§

fn get(&self, key: &<H as Hasher>::Out) -> Option<T>

Look up a given hash into the bytes that hash to it, returning None if the hash is not known.
§

fn contains(&self, key: &<H as Hasher>::Out) -> bool

Check for the existence of a hash-key.
§

fn emplace(&mut self, key: <H as Hasher>::Out, value: T)

Insert a datum item into the DB. Insertions are counted and the equivalent number of remove()s must be performed before the data is considered dead. The caller should ensure that a key only corresponds to one value.
§

fn remove(&mut self, key: &<H as Hasher>::Out)

Remove a datum previously inserted. Insertions can be “owed” such that the same number of insert()s may happen without the data being eventually being inserted into the DB. It can be “owed” more than once. The caller should ensure that a key only corresponds to one value.
§

impl<H, KF, T> PlainDBRef<<H as Hasher>::Out, T> for MemoryDB<H, KF, T>
where H: Hasher, T: Default + PartialEq + for<'a> From<&'a [u8]> + Clone + Send + Sync, KF: Send + Sync + KeyFunction<H>, <KF as KeyFunction<H>>::Key: Borrow<[u8]> + for<'a> From<&'a [u8]>,

§

fn get(&self, key: &<H as Hasher>::Out) -> Option<T>

Look up a given hash into the bytes that hash to it, returning None if the hash is not known.
§

fn contains(&self, key: &<H as Hasher>::Out) -> bool

Check for the existance of a hash-key.
§

impl<H, KF, T> Eq for MemoryDB<H, KF, T>
where H: Hasher, KF: KeyFunction<H>, T: Eq + MaybeDebug,