Struct patricia_trie::triedb::TrieDB
[−]
[src]
pub struct TrieDB<'db> { pub hash_count: usize, // some fields omitted }
A Trie
implementation using a generic HashDB
backing database.
Use it as a Trie
trait object. You can use db()
to get the backing database object.
Use get
and contains
to query values associated with keys in the trie.
Example
extern crate patricia_trie as trie; extern crate hashdb; extern crate memorydb; extern crate ethcore_bigint as bigint; use trie::*; use hashdb::*; use memorydb::*; use bigint::hash::*; fn main() { let mut memdb = MemoryDB::new(); let mut root = H256::new(); TrieDBMut::new(&mut memdb, &mut root).insert(b"foo", b"bar").unwrap(); let t = TrieDB::new(&memdb, &root).unwrap(); assert!(t.contains(b"foo").unwrap()); assert_eq!(t.get(b"foo").unwrap().unwrap(), DBValue::from_slice(b"bar")); }
Fields
hash_count: usize
The number of hashes performed so far in operations on this trie.
Methods
impl<'db> TrieDB<'db>
[src]
fn new(db: &'db HashDB, root: &'db H256) -> Result<Self>
[src]
Create a new trie with the backing database db
and root
Returns an error if root
does not exist
fn db(&'db self) -> &'db HashDB
[src]
Get the backing database.
Trait Implementations
impl<'db> Trie for TrieDB<'db>
[src]
fn iter<'a>(&'a self) -> Result<Box<TrieIterator<Item = TrieItem> + 'a>>
[src]
Returns a depth-first iterator over the elements of trie.
fn root(&self) -> &H256
[src]
Return the root of the trie.
fn get_with<'a, 'key, Q: Query>(
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>> where
'a: 'key,
[src]
&'a self,
key: &'key [u8],
query: Q
) -> Result<Option<Q::Item>> where
'a: 'key,
Search for the key with the given query parameter. See the docs of the Query
trait for more details. Read more
fn is_empty(&self) -> bool
[src]
Is the trie empty?
fn contains(&self, key: &[u8]) -> Result<bool>
[src]
Does the trie contain a given key?
fn get<'a, 'key>(&'a self, key: &'key [u8]) -> Result<Option<DBValue>> where
'a: 'key,
[src]
'a: 'key,
What is the value of the given key in this trie?