Struct exonum::storage::key_set_index::KeySetIndex
[−]
[src]
pub struct KeySetIndex<T, K> { /* fields omitted */ }
A set of items that implement StorageKey
trait.
KeySetIndex
implements a set, storing the elements as keys with empty values.
KeySetIndex
requires that the elements implement the StorageKey
trait.
Methods
impl<T, K> KeySetIndex<T, K>
[src]
fn new<S: AsRef<str>>(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::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let snapshot = db.snapshot(); let name = "name"; let index: KeySetIndex<_, u8> = KeySetIndex::new(name, &snapshot);
fn with_prefix<S: AsRef<str>>(name: S, prefix: Vec<u8>, view: T) -> Self
[src]
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::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let snapshot = db.snapshot(); let name = "name"; let prefix = vec![123]; let index: KeySetIndex<_, u8> = KeySetIndex::with_prefix(name, prefix, &snapshot);
impl<T, K> KeySetIndex<T, K> where
T: AsRef<Snapshot>,
K: StorageKey,
[src]
T: AsRef<Snapshot>,
K: StorageKey,
fn contains(&self, item: &K) -> bool
[src]
Returns true
if the set contains a value.
Examples
use exonum::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let name = "name"; let mut fork = db.fork(); let mut index = KeySetIndex::new(name, &mut fork); assert!(!index.contains(&1)); index.insert(1); assert!(index.contains(&1));
fn iter(&self) -> KeySetIndexIter<K>
[src]
An iterator visiting all elements in ascending order. The iterator element type is K.
Examples
use exonum::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let name = "name"; let snapshot = db.snapshot(); let index: KeySetIndex<_, u8> = KeySetIndex::new(name, &snapshot); for val in index.iter() { println!("{}", val); }
fn iter_from(&self, from: &K) -> KeySetIndexIter<K>
[src]
An iterator visiting all elements in arbitrary order starting from the specified value. The iterator element type is K.
Examples
use exonum::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let name = "name"; let snapshot = db.snapshot(); let index: KeySetIndex<_, u8> = KeySetIndex::new(name, &snapshot); for val in index.iter_from(&2) { println!("{}", val); }
impl<'a, K> KeySetIndex<&'a mut Fork, K> where
K: StorageKey,
[src]
K: StorageKey,
fn insert(&mut self, item: K)
[src]
Adds a value to the set.
Examples
use exonum::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let name = "name"; let mut fork = db.fork(); let mut index = KeySetIndex::new(name, &mut fork); index.insert(1); assert!(index.contains(&1));
fn remove(&mut self, item: &K)
[src]
Removes a value from the set.
Examples
use exonum::storage::{MemoryDB, Database, KeySetIndex}; let db = MemoryDB::new(); let name = "name"; let mut fork = db.fork(); let mut index = KeySetIndex::new(name, &mut fork); index.insert(1); assert!(index.contains(&1)); index.remove(&1); assert!(!index.contains(&1));
fn clear(&mut self)
[src]
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, KeySetIndex}; let db = MemoryDB::new(); let name = "name"; let mut fork = db.fork(); let mut index = KeySetIndex::new(name, &mut fork); index.insert(1); assert!(index.contains(&1)); index.clear(); assert!(!index.contains(&1));
Trait Implementations
impl<T: Debug, K: Debug> Debug for KeySetIndex<T, K>
[src]
impl<'a, T, K> IntoIterator for &'a KeySetIndex<T, K> where
T: AsRef<Snapshot>,
K: StorageKey,
[src]
T: AsRef<Snapshot>,
K: StorageKey,