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]

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]

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));

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));

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);
}

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);
}

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);
}

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);
}

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);
}

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]

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));

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));

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]

Formats the value using the given formatter.

impl<'a, T, K, V> IntoIterator for &'a MapIndex<T, K, V> where
    T: AsRef<Snapshot>,
    K: StorageKey,
    V: StorageValue
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more