[][src]Struct exonum::storage::value_set_index::ValueSetIndex

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.

Methods

impl<T, V> ValueSetIndex<T, V> where
    T: AsRef<dyn Snapshot>,
    V: StorageValue
[src]

pub fn new<S: AsRef<str>>(index_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, ValueSetIndex};

let db = MemoryDB::new();
let name  = "name";
let snapshot = db.snapshot();
let index: ValueSetIndex<_, u8> = ValueSetIndex::new(name, &snapshot);

pub fn new_in_family<S: AsRef<str>, I: StorageKey>(
    family_name: S,
    index_id: &I,
    view: T
) -> Self
[src]

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.

Examples

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

pub fn contains(&self, item: &V) -> bool
[src]

Returns true if the set contains the indicated value.

Examples

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

pub fn contains_by_hash(&self, hash: &Hash) -> bool
[src]

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

Important traits for ValueSetIndexIter<'a, V>
pub fn iter(&self) -> ValueSetIndexIter<V>
[src]

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

Examples

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

Important traits for ValueSetIndexIter<'a, V>
pub fn iter_from(&self, from: &Hash) -> ValueSetIndexIter<V>
[src]

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

Examples

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

Important traits for ValueSetIndexHashes<'a>
pub fn hashes(&self) -> ValueSetIndexHashes
[src]

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

Examples

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

Important traits for ValueSetIndexHashes<'a>
pub fn hashes_from(&self, from: &Hash) -> ValueSetIndexHashes
[src]

Returns an iterator visiting hashes of all elements in ascending order starting from the specified hash. The iterator element type is Hash.

Examples

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

impl<'a, V> ValueSetIndex<&'a mut Fork, V> where
    V: StorageValue
[src]

pub fn insert(&mut self, item: V)
[src]

Adds a value to the set.

Examples

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

pub fn remove(&mut self, item: &V)
[src]

Removes a value from the set.

Examples

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

pub fn remove_by_hash(&mut self, hash: &Hash)
[src]

Removes a value corresponding to the specified hash from the set.

Examples

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

pub fn clear(&mut self)
[src]

Clears the set, removing all values.

Notes

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.

Examples

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

Trait Implementations

impl<'a, T, V> IntoIterator for &'a ValueSetIndex<T, V> where
    T: AsRef<dyn Snapshot>,
    V: StorageValue
[src]

type Item = (Hash, V)

The type of the elements being iterated over.

type IntoIter = ValueSetIndexIter<'a, V>

Which kind of iterator are we turning this into?

impl<T: Debug, V: Debug> Debug for ValueSetIndex<T, V>
[src]

Auto Trait Implementations

impl<T, V> Send for ValueSetIndex<T, V> where
    T: Send,
    V: Send

impl<T, V> Sync for ValueSetIndex<T, V> where
    T: Sync,
    V: Sync

Blanket Implementations

impl<T> From for T
[src]

impl<T, U> Into for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom for T where
    T: From<U>, 
[src]

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

impl<T> Borrow for T where
    T: ?Sized
[src]

impl<T> BorrowMut for T where
    T: ?Sized
[src]

impl<T, U> TryInto for T where
    U: TryFrom<T>, 
[src]

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.

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Erased for T

impl<T> Erased for T

impl<T> Same for T

type Output = T

Should always be Self