Struct hadean_std::list::Leaf [] [src]

pub struct Leaf<T> {
    // some fields omitted
}

A scalable distributed list datastructure. Provides O(1) insertion and deletion. Indexed by a LeafIndex, which can be incremented or decremented in O(1). LeafIndexs for each of the start and end of the list can be retreived in O(1).

Here's an example:

fn main() { let mut leaf: Box<Leaf<u8>> = box unsafe{mem::uninitialized()}; Leaf::init(&mut leaf); let mut replace_start_index = leaf.start(); let mut replace_end_index = replace_start_index.clone_right(); leaf.replace(&mut replace_start_index, &mut replace_end_index, &[1,2,3]); leaf.increment(&mut replace_start_index); leaf.increment(&mut replace_start_index); leaf.replace(&mut replace_start_index, &mut replace_end_index, &[4,5,6]); let mut start = leaf.start(); let mut end = leaf.end(); for num in leaf.read(&mut start, &mut end) { println!("{}", num); } // prints: 1 2 4 5 6 }
let mut leaf: Box<Leaf<u8>> = box unsafe{mem::uninitialized()};
Leaf::init(&mut leaf);
let mut replace_start_index = leaf.start();
let mut replace_end_index = replace_start_index.clone_right();
leaf.replace(&mut replace_start_index, &mut replace_end_index, &[1,2,3]);
leaf.increment(&mut replace_start_index);
leaf.increment(&mut replace_start_index);
leaf.replace(&mut replace_start_index, &mut replace_end_index, &[4,5,6]);
let mut start = leaf.start();
let mut end = leaf.end();
for num in leaf.read(&mut start, &mut end) {
    println!("{}", num);
}
// prints: 1 2 4 5 6

Methods

impl<T> Leaf<T>
[src]

fn init(self_: &mut Self) -> (LeafIndex, LeafIndex)

Initialises a new, empty Leaf<T>. self_ must be uninitialized. Returns the start and end LeafIndexes.

fn replace<I>(&mut self, start: &mut LeafIndex, end: &mut LeafIndex, replacement: I) where I: IntoIterator<Item=T>, I::IntoIter: ExactSizeIterator, T: Copy

Replace the elements between two LeafIndexes. Currently panics if the Leaf runs out of space.

fn len(&self, start: &LeafIndex, end: &LeafIndex) -> usize

Calculate the number of elements between two LeafIndexes.

fn read(&mut self, start: &LeafIndex, end: &LeafIndex) -> Vec<T> where T: Copy

Read the elements between two LeafIndexes into a Vec<T>.

fn increment(&mut self, index: &mut LeafIndex)

Increment a LeafIndex by one element.

fn decrement(&mut self, index: &mut LeafIndex)

Decrement a LeafIndex by one element.