[][src]Struct exonum_merkledb::key_set_index::KeySetIndex

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

A set of key items.

KeySetIndex implements a set that stores the elements as keys with empty values. KeySetIndex requires that elements should implement the BinaryKey trait.

Methods

impl<T, K> KeySetIndex<T, K> where
    T: IndexAccess,
    K: BinaryKey
[src]

pub fn new<S: Into<String>>(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_merkledb::{TemporaryDB, Database, KeySetIndex};

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

pub fn new_in_family<S, I>(family_name: S, index_id: &I, view: T) -> Self where
    I: BinaryKey,
    I: ?Sized,
    S: Into<String>, 
[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_merkledb::{TemporaryDB, Database, KeySetIndex};

let db = TemporaryDB::default();
let snapshot = db.snapshot();
let name = "name";
let index_id = vec![123];
let index: KeySetIndex<_, u8> = KeySetIndex::new_in_family(name, &index_id, &snapshot);

pub fn contains<Q: ?Sized>(&self, item: &Q) -> bool where
    K: Borrow<Q>,
    Q: BinaryKey
[src]

Returns true if the set contains the indicated value.

Examples

use exonum_merkledb::{TemporaryDB, Database, KeySetIndex};

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

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

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

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

Examples

use exonum_merkledb::{TemporaryDB, Database, KeySetIndex};

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

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

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

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

Examples

use exonum_merkledb::{TemporaryDB, Database, KeySetIndex};

let db = TemporaryDB::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);
}

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

Adds a key to the set.

Examples

use exonum_merkledb::{TemporaryDB, Database, KeySetIndex};

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

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

pub fn remove<Q: ?Sized>(&mut self, item: &Q) where
    K: Borrow<Q>,
    Q: BinaryKey
[src]

Removes a key from the set.

Examples

use exonum_merkledb::{TemporaryDB, Database, KeySetIndex};

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

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

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

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_merkledb::{TemporaryDB, Database, KeySetIndex};

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

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

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

Trait Implementations

impl<'a, T, K> IntoIterator for &'a KeySetIndex<T, K> where
    T: IndexAccess,
    K: BinaryKey
[src]

type Item = K::Owned

The type of the elements being iterated over.

type IntoIter = KeySetIndexIter<'a, K>

Which kind of iterator are we turning this into?

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

Auto Trait Implementations

impl<T, K> !Sync for KeySetIndex<T, K>

impl<T, K> Send for KeySetIndex<T, K> where
    K: Send,
    T: Send,
    <T as IndexAccess>::Changes: Send

impl<T, K> Unpin for KeySetIndex<T, K> where
    K: Unpin,
    T: Unpin,
    <T as IndexAccess>::Changes: Unpin

impl<T, K> !RefUnwindSafe for KeySetIndex<T, K>

impl<T, K> UnwindSafe for KeySetIndex<T, K> where
    K: UnwindSafe,
    T: UnwindSafe,
    <T as IndexAccess>::Changes: UnwindSafe

Blanket Implementations

impl<T> From<T> for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

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

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

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

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,