Struct matterdb::indexes::SparseListIndex[][src]

pub struct SparseListIndex<T: RawAccess, V> { /* fields omitted */ }

A list of items similar to ListIndex; however, it may contain “spaces”. For instance, a list might contain six elements with indexes: 1, 2, 3, 5, 7, 8 (missing 4 and 6). And if you try to get the element for index 4 or 6, you will get None.

Later, elements can be added to the spaces, if required. Elements in this list are added to the end of the list and are removed either from the end of the list or from certain indexes.

SparseListIndex has length and capacity. Length is the number of non-empty elements in the list. Capacity is the number of all elements in the list, both empty and non-empty.

SparseListIndex implements an array list, storing an element as a value and using u64 as an index. SparseListIndex requires that elements should implement the BinaryValue trait.

Implementations

impl<T, V> SparseListIndex<T, V> where
    T: RawAccess,
    V: BinaryValue
[src]

pub fn get(&self, index: u64) -> Option<V>[src]

Returns an element at the indicated position or None if the indicated position is out of bounds or if it does not exist.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert_eq!(None, index.get(0));

index.push(42);
assert_eq!(Some(42), index.get(0));
index.push(1);
index.remove(0);
assert_eq!(None, index.get(0));
assert_eq!(Some(1), index.get(1));

pub fn is_empty(&self) -> bool[src]

Returns true if the list contains no elements.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert!(index.is_empty());

index.push(42);
assert!(!index.is_empty());

pub fn capacity(&self) -> u64[src]

Returns the total amount of elements, including empty elements, in the list. The value of capacity is determined by the maximum index of an element ever inserted into the given index.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert_eq!(0, index.capacity());

index.push(10);
index.push(12);
assert_eq!(2, index.capacity());

index.remove(0);

index.push(100);
assert_eq!(3, index.capacity());

pub fn len(&self) -> u64[src]

Returns the total amount of non-empty elements in the list.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert_eq!(0, index.len());

index.push(10);
assert_eq!(1, index.len());

index.remove(0);

index.push(100);
assert_eq!(1, index.len());

pub fn iter(&self) -> Entries<'_, u64, V>

Notable traits for Entries<'_, K, V>

impl<K: ?Sized, V> Iterator for Entries<'_, K, V> where
    K: BinaryKey,
    V: BinaryValue
type Item = (K::Owned, V);
[src]

Returns an iterator over the list elements with corresponding indexes.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());

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

pub fn indexes(&self) -> Keys<'_, u64>

Notable traits for Keys<'_, K>

impl<K: ?Sized> Iterator for Keys<'_, K> where
    K: BinaryKey
type Item = K::Owned;
[src]

Returns an iterator over the indexes of the SparseListIndex.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());

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

pub fn values(&self) -> Values<'_, V>

Notable traits for Values<'_, V>

impl<V> Iterator for Values<'_, V> where
    V: BinaryValue
type Item = V;
[src]

Returns an iterator over list elements.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());

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

pub fn iter_from(&self, from: u64) -> Entries<'_, u64, V>

Notable traits for Entries<'_, K, V>

impl<K: ?Sized, V> Iterator for Entries<'_, K, V> where
    K: BinaryKey,
    V: BinaryValue
type Item = (K::Owned, V);
[src]

Returns an iterator over the list elements starting from the specified position. Elements are yielded with the corresponding index.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.extend([1, 2, 3, 4, 5].iter().cloned());
index.remove(3);

for val in index.iter_from(3) {
    println!("{:?}", val);
}

impl<T, V> SparseListIndex<T, V> where
    T: RawAccessMut,
    V: BinaryValue
[src]

pub fn push(&mut self, value: V)[src]

Appends an element to the back of the SparseListIndex.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.push(1);
assert!(!index.is_empty());

pub fn remove(&mut self, index: u64) -> Option<V>[src]

Removes the element with the given index from the list and returns it, or returns None if it is empty.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert_eq!(0, index.capacity());

index.push(10);
index.push(12);

assert_eq!(Some(10), index.remove(0));
assert_eq!(None, index.remove(0));
assert_eq!(2, index.capacity());
assert_eq!(1, index.len());
assert_eq!(Some(12), index.remove(1));
assert_eq!(2, index.capacity());

pub fn extend<I>(&mut self, iter: I) where
    I: IntoIterator<Item = V>, 
[src]

Extends the list with the contents of an iterator.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert!(index.is_empty());

index.extend([1, 2, 3].iter().cloned());
assert_eq!(3, index.capacity());

pub fn set(&mut self, index: u64, value: V) -> Option<V>[src]

Changes a value at a specified position. If the position contains an empty value, it also increments the elements count. If the index value of the new element is greater than the current capacity, the capacity of the list is considered index + 1 and all further elements without specific index values will be appended after this index.

Returns the value of a previous element at the indicated position or None if it is empty.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.push(1);
assert_eq!(Some(1), index.get(0));

index.set(0, 10);
assert_eq!(Some(10), index.get(0));

pub fn clear(&mut self)[src]

Clears the list, 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 matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");

index.push(1);
assert!(!index.is_empty());

index.clear();
assert!(index.is_empty());

pub fn pop(&mut self) -> Option<V>[src]

Removes the first element from the SparseListIndex and returns it, or returns None if it is empty.

Examples

use matterdb::{access::CopyAccessExt, TemporaryDB, Database, SparseListIndex};

let db = TemporaryDB::new();
let mut fork = db.fork();
let mut index = fork.get_sparse_list("name");
assert_eq!(None, index.pop());

index.push(1);
assert_eq!(Some(1), index.pop());

Trait Implementations

impl<T: Debug + RawAccess, V: Debug> Debug for SparseListIndex<T, V>[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl<T, V> FromAccess<T> for SparseListIndex<T::Base, V> where
    T: Access,
    V: BinaryValue
[src]

fn from_access(access: T, addr: IndexAddress) -> Result<Self, AccessError>[src]

Constructs the object at the given address. Read more

fn from_root(access: T) -> Result<Self, AccessError>[src]

Constructs the object from the root of the access. Read more

impl<T, V> IndexIterator for SparseListIndex<T, V> where
    T: RawAccess,
    V: BinaryValue
[src]

type Key = u64

Type encompassing index keys.

type Value = V

Type encompassing index values.

fn index_iter(&self, from: Option<&u64>) -> Entries<'_, u64, V>

Notable traits for Entries<'_, K, V>

impl<K: ?Sized, V> Iterator for Entries<'_, K, V> where
    K: BinaryKey,
    V: BinaryValue
type Item = (K::Owned, V);
[src]

Continues iteration from the specified position. If from is None, starts the iteration from scratch. Read more

impl<'a, T, V> IntoIterator for &'a SparseListIndex<T, V> where
    T: RawAccess,
    V: BinaryValue
[src]

type Item = (u64, V)

The type of the elements being iterated over.

type IntoIter = Entries<'a, u64, V>

Which kind of iterator are we turning this into?

fn into_iter(self) -> Self::IntoIter[src]

Creates an iterator from a value. Read more

Auto Trait Implementations

impl<T, V> RefUnwindSafe for SparseListIndex<T, V> where
    T: RefUnwindSafe,
    V: RefUnwindSafe,
    <T as RawAccess>::Changes: RefUnwindSafe

impl<T, V> Send for SparseListIndex<T, V> where
    T: Send,
    V: Send,
    <T as RawAccess>::Changes: Send

impl<T, V> Sync for SparseListIndex<T, V> where
    T: Sync,
    V: Sync,
    <T as RawAccess>::Changes: Sync

impl<T, V> Unpin for SparseListIndex<T, V> where
    T: Unpin,
    V: Unpin,
    <T as RawAccess>::Changes: Unpin

impl<T, V> UnwindSafe for SparseListIndex<T, V> where
    T: UnwindSafe,
    V: UnwindSafe,
    <T as RawAccess>::Changes: UnwindSafe

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

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

pub fn from(t: T) -> T[src]

Performs the conversion.

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

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> Pointable for T

pub const ALIGN: usize

The alignment of pointer.

type Init = T

The type for initializers.

pub unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more

pub unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more

pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more

pub unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more

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.

pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]

Performs the conversion.

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.

pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>[src]

Performs the conversion.