Struct SkipList

Source
pub struct SkipList<T> { /* private fields */ }

Implementations§

Source§

impl<T: Ord> SkipList<T>

Source

pub fn new() -> Self

Creates a new, empty SkipList.

Source

pub fn len(&self) -> usize

Returns the number of elements in the list.

Source

pub fn is_empty(&self) -> bool

Wrapper for len() that returns a Boolean indicating whether the list is empty.

Source

pub fn get<Q>(&self, key: &Q) -> Option<&T>
where Q: Ord + ?Sized, T: Borrow<Q>,

Returns the a reference to the entry associated with the search key if it exists in the list, otherwise returns None to indicate that the key is not in the list.

Represents Pugh’s canonical Search operation as described in the original paper.

Source

pub fn contains<Q>(&self, key: &Q) -> bool
where Q: Ord + ?Sized, T: Borrow<Q>,

Returns a Boolean indicating whether the supplied search key exists in the list.

Wrapper for the public get() operation, which itself wraps the private skip_search() operation.

Source

pub fn insert(&mut self, entry: T)

Inserts a new entry into the skip list.

Allows duplicates, where ordering is determined by insertion order such that the most recent duplicates come before older entries.

Source

pub fn remove<Q>(&mut self, key: &Q) -> Option<T>
where Q: Ord + ?Sized, T: Borrow<Q>,

Removes and returns the value for a given key, if it exists in the list. Returns None if the key does not exist in the list.

This function does not technically adhere to Pugh’s original removal algorithm. It uses Vec::swap_remove for simplified backing list compaction with the side effect of re-ordering remaining elements. The resultant removal time is therefore O(n * height), which is O(n * log(n)) expected, and O(n^2) worst case.

Source

pub fn get_kth(&self, k: usize) -> Option<&T>

Returns the Kth value in the list, if it exists.

Source

pub fn range<Q, R>(&self, range: R) -> RangeIter<'_, T, Q, R>
where Q: Ord + ?Sized, T: Borrow<Q>, R: RangeBounds<Q>,

Returns an inclusive iterator over a range of values in the list from start to end.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over borrowed values in the list.

Trait Implementations§

Source§

impl<T: Ord> Default for SkipList<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'a, T: Ord> IntoIterator for &'a SkipList<T>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for SkipList<T>

§

impl<T> RefUnwindSafe for SkipList<T>
where T: RefUnwindSafe,

§

impl<T> Send for SkipList<T>
where T: Send,

§

impl<T> Sync for SkipList<T>
where T: Sync,

§

impl<T> Unpin for SkipList<T>
where T: Unpin,

§

impl<T> UnwindSafe for SkipList<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

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

Performs the conversion.
§

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

§

fn vzip(self) -> V