Struct exonum::storage::key_set_index::KeySetIndex [] [src]

pub struct KeySetIndex<T, K> { /* fields omitted */ }

A set of items that implement StorageKey trait.

KeySetIndex implements a set, storing the elements as keys with empty values. KeySetIndex requires that the elements implement the StorageKey trait.

Methods

impl<T, K> KeySetIndex<T, K>
[src]

[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, KeySetIndex};

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

[src]

Creates a new index representation based on the name, 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, KeySetIndex};

let db = MemoryDB::new();
let snapshot = db.snapshot();
let name = "name";
let prefix = vec![123];
let index: KeySetIndex<_, u8> = KeySetIndex::with_prefix(name, prefix, &snapshot);

impl<T, K> KeySetIndex<T, K> where
    T: AsRef<Snapshot>,
    K: StorageKey
[src]

[src]

Returns true if the set contains a value.

Examples

use exonum::storage::{MemoryDB, Database, KeySetIndex};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = KeySetIndex::new(name, &mut fork);
assert!(!index.contains(&1));

index.insert(1);
assert!(index.contains(&1));

[src]

An iterator visiting all elements in ascending order. The iterator element type is K.

Examples

use exonum::storage::{MemoryDB, Database, KeySetIndex};

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

for val in index.iter() {
    println!("{}", val);
}

[src]

An iterator visiting all elements in arbitrary order starting from the specified value. The iterator element type is K.

Examples

use exonum::storage::{MemoryDB, Database, KeySetIndex};

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

for val in index.iter_from(&2) {
    println!("{}", val);
}

impl<'a, K> KeySetIndex<&'a mut Fork, K> where
    K: StorageKey
[src]

[src]

Adds a value to the set.

Examples

use exonum::storage::{MemoryDB, Database, KeySetIndex};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = KeySetIndex::new(name, &mut fork);

index.insert(1);
assert!(index.contains(&1));

[src]

Removes a value from the set.

Examples

use exonum::storage::{MemoryDB, Database, KeySetIndex};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = KeySetIndex::new(name, &mut fork);

index.insert(1);
assert!(index.contains(&1));

index.remove(&1);
assert!(!index.contains(&1));

[src]

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, KeySetIndex};

let db = MemoryDB::new();
let name = "name";
let mut fork = db.fork();
let mut index = KeySetIndex::new(name, &mut fork);

index.insert(1);
assert!(index.contains(&1));

index.clear();
assert!(!index.contains(&1));

Trait Implementations

impl<T: Debug, K: Debug> Debug for KeySetIndex<T, K>
[src]

[src]

Formats the value using the given formatter.

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

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

[src]

Creates an iterator from a value. Read more