Struct stable_skiplist::skiplist::SkipList [] [src]

pub struct SkipList<T> { /* fields omitted */ }

SkipList provides a way of storing elements and provides efficient way to access, insert and remove nodes.

Methods

impl<T> SkipList<T>
[src]

Create a new skiplist with the default number of 16 levels.

Examples

use skiplist::SkipList;

let mut skiplist: SkipList<i64> = SkipList::new();

Constructs a new, empty skiplist with the optimal number of levels for the intended capacity. Specifically, it uses floor(log2(capacity)) number of levels, ensuring that only a few nodes occupy the highest level.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::with_capacity(100);
skiplist.extend(0..100);

Clears the skiplist, removing all values.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
skiplist.clear();
assert!(skiplist.is_empty());

Returns the number of elements in the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
assert_eq!(skiplist.len(), 10);

Returns true if the skiplist contains no elements.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert!(skiplist.is_empty());

skiplist.push_back(1);
assert!(!skiplist.is_empty());

Insert the element into the skiplist at the given index, shifting all subsequent nodes down.

Panics

Panics if the insert index is greater than the length of the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();

skiplist.insert(0, 0);
skiplist.insert(5, 1);
assert_eq!(skiplist.len(), 2);
assert!(!skiplist.is_empty());

Insert the element into the front of the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.push_front(1);
skiplist.push_front(2);

Insert the element into the back of the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.push_back(1);
skiplist.push_back(2);

Provides a reference to the front element, or None if the skiplist is empty.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert_eq!(skiplist.front(), None);

skiplist.push_back(1);
skiplist.push_back(2);
assert_eq!(skiplist.front(), Some(&1));

Provides a mutable reference to the front element, or None if the skiplist is empty.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert_eq!(skiplist.front(), None);

skiplist.push_back(1);
skiplist.push_back(2);
assert_eq!(skiplist.front_mut(), Some(&mut 1));

Provides a reference to the back element, or None if the skiplist is empty.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert_eq!(skiplist.back(), None);

skiplist.push_back(1);
skiplist.push_back(2);
assert_eq!(skiplist.back(), Some(&2));

Provides a reference to the back element, or None if the skiplist is empty.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert_eq!(skiplist.back(), None);

skiplist.push_back(1);
skiplist.push_back(2);
assert_eq!(skiplist.back_mut(), Some(&mut 2));

Provides a reference to the element at the given index, or None if the skiplist is empty or the index is out of bounds.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert_eq!(skiplist.get(0), None);
skiplist.extend(0..10);
assert_eq!(skiplist.get(0), Some(&0));
assert_eq!(skiplist.get(10), None);

Provides a mutable reference to the element at the given index, or None if the skiplist is empty or the index is out of bounds.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
assert_eq!(skiplist.get_mut(0), None);
skiplist.extend(0..10);
assert_eq!(skiplist.get_mut(0), Some(&mut 0));
assert_eq!(skiplist.get_mut(10), None);

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

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.push_back(1);
skiplist.push_back(2);

assert_eq!(skiplist.pop_front(), Some(1));
assert_eq!(skiplist.pop_front(), Some(2));
assert_eq!(skiplist.pop_front(), None);

Removes the last element and returns it, or None if the sequence is empty.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.push_back(1);
skiplist.push_back(2);

assert_eq!(skiplist.pop_back(), Some(2));
assert_eq!(skiplist.pop_back(), Some(1));
assert_eq!(skiplist.pop_back(), None);

Removes and returns an element with the given index.

Panics

Panics is the index is out of bounds.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
assert_eq!(skiplist.remove(4), 4);
assert_eq!(skiplist.remove(4), 5);

Retains only the elements specified by the predicate.

In other words, remove all elements e such that f(&e) returns false. This method operates in place.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
skiplist.retain(|&x| x%2 == 0);

Get an owning iterator over the entries of the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
for i in skiplist.into_iter() {
    println!("Value: {}", i);
}

Creates an iterator over the entries of the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
for i in skiplist.iter() {
    println!("Value: {}", i);
}

Creates an mutable iterator over the entries of the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
for i in skiplist.iter_mut() {
    println!("Value: {}", i);
}

Constructs a double-ended iterator over a sub-range of elements in the skiplist, starting at min, and ending at max. If min is Unbounded, then it will be treated as "negative infinity", and if max is Unbounded, then it will be treated as "positive infinity". Thus range(Unbounded, Unbounded) will yield the whole collection.

Examples

use skiplist::SkipList;
use skiplist::Bound::{Included, Unbounded};

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
for i in skiplist.range(Included(3), Included(7)) {
    println!("Value: {}", i);
}
assert_eq!(Some(&4), skiplist.range(Included(4), Unbounded).next());

Constructs a mutable double-ended iterator over a sub-range of elements in the skiplist, starting at min, and ending at max. If min is Unbounded, then it will be treated as "negative infinity", and if max is Unbounded, then it will be treated as "positive infinity". Thus range(Unbounded, Unbounded) will yield the whole collection.

Examples

use skiplist::SkipList;
use skiplist::Bound::{Included, Unbounded};

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
for i in skiplist.range_mut(Included(3), Included(7)) {
    println!("Value: {}", i);
}
assert_eq!(Some(&mut 4), skiplist.range_mut(Included(4), Unbounded).next());

impl<T> SkipList<T> where
    T: PartialEq
[src]

Returns true if the value is contained in the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.extend(0..10);
assert!(skiplist.contains(&4));
assert!(!skiplist.contains(&15));

Removes all consecutive repeated elements in the skiplist.

Examples

use skiplist::SkipList;

let mut skiplist = SkipList::new();
skiplist.push_back(0);
skiplist.push_back(0);
assert_eq!(skiplist.len(), 2);
skiplist.dedup();
assert_eq!(skiplist.len(), 1);

Trait Implementations

impl<T: Send> Send for SkipList<T>
[src]

impl<T: Sync> Sync for SkipList<T>
[src]

impl<T> Drop for SkipList<T>
[src]

A method called when the value goes out of scope. Read more

impl<T: PartialOrd> Default for SkipList<T>
[src]

Returns the "default value" for a type. Read more

impl<A, B> PartialEq<SkipList<B>> for SkipList<A> where
    A: PartialEq<B>, 
[src]

This implementation of PartialEq only checks that the values are equal; it does not check for equivalence of other features (such as the ordering function and the node levels). Furthermore, this uses T's implementation of PartialEq and does not use the owning skiplist's comparison function.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl<T> Eq for SkipList<T> where
    T: Eq
[src]

impl<A, B> PartialOrd<SkipList<B>> for SkipList<A> where
    A: PartialOrd<B>, 
[src]

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

impl<T> Ord for SkipList<T> where
    T: Ord
[src]

This method returns an Ordering between self and other. Read more

impl<T> Extend<T> for SkipList<T>
[src]

Extends a collection with the contents of an iterator. Read more

impl<T> Index<usize> for SkipList<T>
[src]

The returned type after indexing

The method for the indexing (container[index]) operation

impl<T> Debug for SkipList<T> where
    T: Debug
[src]

Formats the value using the given formatter.

impl<T> Display for SkipList<T> where
    T: Display
[src]

Formats the value using the given formatter. Read more

impl<T> IntoIterator for SkipList<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, T> IntoIterator for &'a SkipList<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, T> IntoIterator for &'a mut SkipList<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<T> FromIterator<T> for SkipList<T> where
    T: PartialOrd
[src]

Creates a value from an iterator. Read more

impl<T: Hash> Hash for SkipList<T>
[src]

Feeds this value into the given [Hasher]. Read more

Feeds a slice of this type into the given [Hasher]. Read more