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]

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]

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

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

An iterator visiting all elements in arbitrary order. The iterator element type is V.

An iterator visiting all elements in arbitrary order starting from the specified hash of a value. The iterator element type is V.

An iterator visiting hashes of all elements in ascending order. The iterator element type is Hash.

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]

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

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

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

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]

Formats the value using the given formatter.

impl<'a, T, V> IntoIterator for &'a ValueSetIndex<T, V> where
    T: AsRef<Snapshot>,
    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