pub struct ValueSetIndex<T, V> { /* fields omitted */ }
A set of value items.
ValueSetIndex
implements a set, storing an element as a value and using its hash as a key.
ValueSetIndex
requires that elements should implement the StorageValue
trait.
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.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ValueSetIndex<_, u8> = ValueSetIndex::new(name, &snapshot);
Creates a new index representation based on the name, index ID in family
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.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let snapshot = db.snapshot();
let name = "name";
let index_id = vec![123];
let index: ValueSetIndex<_, u8> = ValueSetIndex::new_in_family(name, &index_id, &snapshot);
Returns true
if the set contains the indicated value.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ValueSetIndex::new(name, &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.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
use exonum::crypto;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ValueSetIndex::new(name, &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));
Returns an iterator visiting all elements in arbitrary order. The iterator element type is V.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ValueSetIndex<_, u8> = ValueSetIndex::new(name, &snapshot);
for val in index.iter() {
println!("{:?}", val);
}
Returns an iterator visiting all elements in arbitrary order starting from the specified hash of
a value. The iterator element type is V.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ValueSetIndex<_, u8> = ValueSetIndex::new(name, &snapshot);
let hash = Hash::default();
for val in index.iter_from(&hash) {
println!("{:?}", val);
}
Returns an iterator visiting hashes of all elements in ascending order. The iterator element type
is Hash.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ValueSetIndex<_, u8> = ValueSetIndex::new(name, &snapshot);
for val in index.hashes() {
println!("{:?}", val);
}
Returns an iterator visiting hashes of all elements in ascending order starting from the specified
hash. The iterator element type is Hash.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
use exonum::crypto::Hash;
let db = MemoryDB::new();
let name = "name";
let snapshot = db.snapshot();
let index: ValueSetIndex<_, u8> = ValueSetIndex::new(name, &snapshot);
let hash = Hash::default();
for val in index.hashes_from(&hash) {
println!("{:?}", val);
}
Adds a value to the set.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ValueSetIndex::new(name, &mut fork);
index.insert(1);
assert!(index.contains(&1));
Removes a value from the set.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ValueSetIndex::new(name, &mut fork);
index.insert(1);
assert!(index.contains(&1));
index.remove(&1);
assert!(!index.contains(&1));
Removes a value corresponding to the specified hash from the set.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
use exonum::crypto;
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ValueSetIndex::new(name, &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.
Currently, this method is not optimized to delete a 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.
use exonum::storage::{MemoryDB, Database, ValueSetIndex};
let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = ValueSetIndex::new(name, &mut fork);
index.insert(1);
assert!(index.contains(&1));
index.clear();
assert!(!index.contains(&1));
Formats the value using the given formatter. Read more
type Error = !
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
type Error = <U as TryFrom<T>>::Error
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static