Struct exonum::storage::value_set_index::ValueSetIndex
[−]
[src]
pub struct ValueSetIndex<T, V> { /* fields omitted */ }
A set of items that implement StorageValue
trait.
ValueSetIndex
implements a set, storing the element as values using its hash as a key.
ValueSetIndex
requires that the elements implement the StorageValue
trait.
Methods
impl<T, V> ValueSetIndex<T, V>
[src]
fn new(prefix: Vec<u8>, view: T) -> Self
Creates a new index representation based on the 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, ValueSetIndex}; let db = MemoryDB::new(); let snapshot = db.snapshot(); let prefix = vec![1, 2, 3]; let index: ValueSetIndex<_, u8> = ValueSetIndex::new(prefix, &snapshot);
impl<T, V> ValueSetIndex<T, V> where
T: AsRef<Snapshot>,
V: StorageValue,
[src]
T: AsRef<Snapshot>,
V: StorageValue,
fn contains(&self, item: &V) -> bool
Returns true
if the set contains a value.
Examples
use exonum::storage::{MemoryDB, Database, ValueSetIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = ValueSetIndex::new(vec![1, 2, 3], &mut fork); assert!(!index.contains(&1)); index.insert(1); assert!(index.contains(&1));
fn contains_by_hash(&self, hash: &Hash) -> bool
Returns true
if the set contains a value with the specified hash.
Examples
use exonum::storage::{MemoryDB, Database, ValueSetIndex}; use exonum::crypto; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = ValueSetIndex::new(vec![1, 2, 3], &mut fork); let data = vec![1, 2, 3]; let data_hash = crypto::hash(&data); assert!(!index.contains_by_hash(&data_hash)); index.insert(data); assert!(index.contains_by_hash(&data_hash));
fn iter(&self) -> ValueSetIndexIter<V>
An iterator visiting all elements in arbitrary order. The iterator element type is V.
fn iter_from(&self, from: &Hash) -> ValueSetIndexIter<V>
An iterator visiting all elements in arbitrary order starting from the specified hash of a value. The iterator element type is V.
fn hashes(&self) -> ValueSetIndexHashes
An iterator visiting hashes of all elements in ascending order. The iterator element type is Hash.
fn hashes_from(&self, from: &Hash) -> ValueSetIndexHashes
An iterator visiting hashes of all elements in ascending order starting from the specified hash. The iterator element type is Hash.
impl<'a, V> ValueSetIndex<&'a mut Fork, V> where
V: StorageValue,
[src]
V: StorageValue,
fn insert(&mut self, item: V)
Adds a value to the set.
Examples
use exonum::storage::{MemoryDB, Database, ValueSetIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = ValueSetIndex::new(vec![1, 2, 3], &mut fork); index.insert(1); assert!(index.contains(&1));
fn remove(&mut self, item: &V)
Removes a value from the set.
Examples
use exonum::storage::{MemoryDB, Database, ValueSetIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = ValueSetIndex::new(vec![1, 2, 3], &mut fork); index.insert(1); assert!(index.contains(&1)); index.remove(&1); assert!(!index.contains(&1));
fn remove_by_hash(&mut self, hash: &Hash)
Removes a value from the set by the specified hash.
Examples
use exonum::storage::{MemoryDB, Database, ValueSetIndex}; use exonum::crypto; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = ValueSetIndex::new(vec![1, 2, 3], &mut fork); let data = vec![1, 2, 3]; let data_hash = crypto::hash(&data); index.insert(data); assert!(index.contains_by_hash(&data_hash)); index.remove_by_hash(&data_hash); assert!(!index.contains_by_hash(&data_hash));
fn clear(&mut self)
Clears the set, removing all values.
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, ValueSetIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = ValueSetIndex::new(vec![1, 2, 3], &mut fork); index.insert(1); assert!(index.contains(&1)); index.clear(); assert!(!index.contains(&1));
Trait Implementations
impl<T: Debug, V: Debug> Debug for ValueSetIndex<T, V>
[src]
impl<'a, T, V> IntoIterator for &'a ValueSetIndex<T, V> where
T: AsRef<Snapshot>,
V: StorageValue,
[src]
T: AsRef<Snapshot>,
V: StorageValue,