Struct exonum::storage::map_index::MapIndex
[−]
[src]
pub struct MapIndex<T, K, V> { /* fields omitted */ }
A map of keys and values.
MapIndex
requires that the keys implement the StorageKey
trait and the values implement
StorageValue
trait.
Methods
impl<T, K, V> MapIndex<T, K, 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, MapIndex}; let db = MemoryDB::new(); let snapshot = db.snapshot(); let prefix = vec![1, 2, 3]; let index: MapIndex<_, u8, u8> = MapIndex::new(prefix, &snapshot);
impl<T, K, V> MapIndex<T, K, V> where
T: AsRef<Snapshot>,
K: StorageKey,
V: StorageValue,
[src]
T: AsRef<Snapshot>,
K: StorageKey,
V: StorageValue,
fn get(&self, key: &K) -> Option<V>
Returns a value corresponding to the key.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); assert!(index.get(&1).is_none()); index.put(&1, 2); assert_eq!(Some(2), index.get(&1));
fn contains(&self, key: &K) -> bool
Returns true
if the map contains a value for the specified key.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); assert!(!index.contains(&1)); index.put(&1, 2); assert!(index.contains(&1));
fn iter(&self) -> MapIndexIter<K, V>
Returns an iterator over the entries of the map in ascending order. The iterator element type is (K, V).
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); index.put(&3, 4); index.put(&5, 6); for v in index.iter() { println!("{:?}", v); }
fn keys(&self) -> MapIndexKeys<K>
Returns an iterator over the keys of the map in ascending order. The iterator element type is K.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); index.put(&3, 4); index.put(&5, 6); for key in index.keys() { println!("{}", key); }
fn values(&self) -> MapIndexValues<V>
Returns an iterator over the values of the map in ascending order of keys. The iterator element type is V.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); index.put(&3, 4); index.put(&5, 6); for val in index.values() { println!("{}", val); }
fn iter_from(&self, from: &K) -> MapIndexIter<K, V>
Returns an iterator over the entries of the map in ascending order starting from the specified key. The iterator element type is (K, V).
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); index.put(&3, 4); index.put(&5, 6); for v in index.iter_from(&2) { println!("{:?}", v); }
fn keys_from(&self, from: &K) -> MapIndexKeys<K>
Returns an iterator over the keys of the map in ascending order starting from the specified key. The iterator element type is K.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); index.put(&3, 4); index.put(&5, 6); for key in index.keys_from(&2) { println!("{}", key); }
fn values_from(&self, from: &K) -> MapIndexValues<V>
Returns an iterator over the values of the map in ascending order of keys starting from the specified key. The iterator element type is V.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); index.put(&3, 4); index.put(&5, 6); for val in index.values_from(&2) { println!("{}", val); }
impl<'a, K, V> MapIndex<&'a mut Fork, K, V> where
K: StorageKey,
V: StorageValue,
[src]
K: StorageKey,
V: StorageValue,
fn put(&mut self, key: &K, value: V)
Inserts the key-value pair into the map.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); assert!(index.contains(&1));
fn remove(&mut self, key: &K)
Removes the key from the map.
Examples
use exonum::storage::{MemoryDB, Database, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); assert!(index.contains(&1)); index.remove(&1); assert!(!index.contains(&1));
fn clear(&mut self)
Clears the map, removing all entries.
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, MapIndex}; let db = MemoryDB::new(); let mut fork = db.fork(); let mut index = MapIndex::new(vec![1, 2, 3], &mut fork); index.put(&1, 2); assert!(index.contains(&1)); index.clear(); assert!(!index.contains(&1));
Trait Implementations
impl<T: Debug, K: Debug, V: Debug> Debug for MapIndex<T, K, V>
[src]
impl<'a, T, K, V> IntoIterator for &'a MapIndex<T, K, V> where
T: AsRef<Snapshot>,
K: StorageKey,
V: StorageValue,
[src]
T: AsRef<Snapshot>,
K: StorageKey,
V: StorageValue,