Skip to main content

SkipList

Struct SkipList 

Source
pub struct SkipList<K, V, C = BasicComparator, A: SkiplistAllocator = TursoAllocator> { /* private fields */ }
Expand description

A lock-free skip list.

Implementations§

Source§

impl<K, V> SkipList<K, V>

Source

pub fn new(collector: Collector) -> Self

Returns a new, empty skip list.

Source§

impl<K, V, A: SkiplistAllocator> SkipList<K, V, BasicComparator, A>

Source

pub fn new_in(collector: Collector, alloc: A) -> Self

Returns a new, empty skip list that allocates its nodes in alloc.

Source§

impl<K, V, C> SkipList<K, V, C>

Source

pub fn with_comparator(collector: Collector, comparator: C) -> Self

Returns a new, empty skip list using the given comparator.

Source§

impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>

Source

pub fn with_comparator_in(collector: Collector, comparator: C, alloc: A) -> Self

Returns a new, empty skip list using the given comparator, allocating its nodes in alloc.

Source

pub fn is_empty(&self) -> bool

Returns true if the skip list is empty.

Source

pub fn len(&self) -> usize

Returns the number of entries in the skip list.

If the skip list is being concurrently modified, consider the returned number just an approximation without any guarantees.

Source§

impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>
where C: Comparator<K>,

Source

pub fn front<'a: 'g, 'g>( &'a self, guard: &'g Guard, ) -> Option<Entry<'a, 'g, K, V, C, A>>

Returns the entry with the smallest key.

Source

pub fn back<'a: 'g, 'g>( &'a self, guard: &'g Guard, ) -> Option<Entry<'a, 'g, K, V, C, A>>

Returns the entry with the largest key.

Source

pub fn contains_key<Q>(&self, key: &Q, guard: &Guard) -> bool
where C: Comparator<K, Q>, Q: ?Sized,

Returns true if the map contains a value for the specified key.

Source

pub fn get<'a: 'g, 'g, Q>( &'a self, key: &Q, guard: &'g Guard, ) -> Option<Entry<'a, 'g, K, V, C, A>>
where C: Comparator<K, Q>, Q: ?Sized,

Returns an entry with the specified key.

Source

pub fn lower_bound<'a: 'g, 'g, Q>( &'a self, bound: Bound<&Q>, guard: &'g Guard, ) -> Option<Entry<'a, 'g, K, V, C, A>>
where C: Comparator<K, Q>, Q: ?Sized,

Returns an Entry pointing to the lowest element whose key is above the given bound. If no such element is found then None is returned.

Source

pub fn upper_bound<'a: 'g, 'g, Q>( &'a self, bound: Bound<&Q>, guard: &'g Guard, ) -> Option<Entry<'a, 'g, K, V, C, A>>
where C: Comparator<K, Q>, Q: ?Sized,

Returns an Entry pointing to the highest element whose key is below the given bound. If no such element is found then None is returned.

Source

pub fn get_or_insert( &self, key: K, value: V, guard: &Guard, ) -> RefEntry<'_, K, V, C, A>

Finds an entry with the specified key, or inserts a new key-value pair if none exist.

Source

pub fn try_get_or_insert( &self, key: K, value: V, guard: &Guard, ) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>

Fallible version of get_or_insert: returns an error instead of aborting the process when node allocation fails.

On error the skip list is unchanged and both key and value are dropped.

Source

pub fn get_or_insert_with<F>( &self, key: K, value: F, guard: &Guard, ) -> RefEntry<'_, K, V, C, A>
where F: FnOnce() -> V,

Finds an entry with the specified key, or inserts a new key-value pair if none exist, where value is calculated with a function.

Note: Another thread may write key value first, leading to the result of this closure discarded. If closure is modifying some other state (such as shared counters or shared objects), it may lead to undesired behaviour such as counters being changed without result of closure inserted

Source

pub fn try_get_or_insert_with<F>( &self, key: K, value: F, guard: &Guard, ) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>
where F: FnOnce() -> V,

Fallible version of get_or_insert_with: returns an error instead of aborting the process when node allocation fails.

On error the skip list is unchanged and both key and the value built by value are dropped.

Source

pub fn iter<'a: 'g, 'g>(&'a self, guard: &'g Guard) -> Iter<'a, 'g, K, V, C, A>

Returns an iterator over all entries in the skip list.

Source

pub fn ref_iter(&self) -> RefIter<'_, K, V, C, A>

Returns an iterator over all entries in the skip list.

Source

pub fn range<'a: 'g, 'g, Q, R>( &'a self, range: R, guard: &'g Guard, ) -> Range<'a, 'g, Q, R, K, V, C, A>
where C: Comparator<K, Q>, R: RangeBounds<Q>, Q: ?Sized,

Returns an iterator over a subset of entries in the skip list.

Source

pub fn ref_range<'a, Q, R>(&'a self, range: R) -> RefRange<'a, Q, R, K, V, C, A>
where C: Comparator<K, Q>, R: RangeBounds<Q>, Q: ?Sized,

Returns an iterator over a subset of entries in the skip list.

Source§

impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>
where C: Comparator<K>, K: Send + 'static, V: Send + 'static,

Source

pub fn insert( &self, key: K, value: V, guard: &Guard, ) -> RefEntry<'_, K, V, C, A>

Inserts a key-value pair into the skip list and returns the new entry.

If there is an existing entry with this key, it will be removed before inserting the new one.

Source

pub fn try_insert( &self, key: K, value: V, guard: &Guard, ) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>

Fallible version of insert: returns an error instead of aborting the process when node allocation fails.

On error the skip list is unchanged and both key and value are dropped.

Source

pub fn compare_insert<F>( &self, key: K, value: V, compare_fn: F, guard: &Guard, ) -> RefEntry<'_, K, V, C, A>
where F: Fn(&V) -> bool,

Inserts a key-value pair into the skip list and returns the new entry.

If there is an existing entry with this key and compare(entry.value) returns true, it will be removed before inserting the new one. The closure will not be called if the key is not present.

Source

pub fn try_compare_insert<F>( &self, key: K, value: V, compare_fn: F, guard: &Guard, ) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>
where F: Fn(&V) -> bool,

Fallible version of compare_insert: returns an error instead of aborting the process when node allocation fails.

On error the skip list is unchanged and both key and value are dropped.

Source

pub fn remove<Q>( &self, key: &Q, guard: &Guard, ) -> Option<RefEntry<'_, K, V, C, A>>
where C: Comparator<K, Q>, Q: ?Sized,

Removes an entry with the specified key from the map and returns it.

Source

pub fn pop_front(&self, guard: &Guard) -> Option<RefEntry<'_, K, V, C, A>>

Removes an entry from the front of the skip list.

Source

pub fn pop_back(&self, guard: &Guard) -> Option<RefEntry<'_, K, V, C, A>>

Removes an entry from the back of the skip list.

Source

pub fn clear(&self, guard: &mut Guard)

Iterates over the map and removes every entry.

Trait Implementations§

Source§

impl<K, V, C, A: SkiplistAllocator> Debug for SkipList<K, V, C, A>
where K: Debug, V: Debug,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<K, V, C, A: SkiplistAllocator> Drop for SkipList<K, V, C, A>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<K, V, C, A: SkiplistAllocator> IntoIterator for SkipList<K, V, C, A>

Source§

type Item = (K, V)

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<K, V, A>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<K: Send + Sync, V: Send + Sync, C: Send + Sync, A: SkiplistAllocator> Send for SkipList<K, V, C, A>

Source§

impl<K: Send + Sync, V: Send + Sync, C: Send + Sync, A: SkiplistAllocator> Sync for SkipList<K, V, C, A>

Auto Trait Implementations§

§

impl<K, V, C = BasicComparator, A = TursoAllocator> !Freeze for SkipList<K, V, C, A>

§

impl<K, V, C = BasicComparator, A = TursoAllocator> !RefUnwindSafe for SkipList<K, V, C, A>

§

impl<K, V, C = BasicComparator, A = TursoAllocator> !UnwindSafe for SkipList<K, V, C, A>

§

impl<K, V, C, A> Unpin for SkipList<K, V, C, A>
where Head<K, V>: Unpin, C: Unpin, A: Unpin,

§

impl<K, V, C, A> UnsafeUnpin for SkipList<K, V, C, A>
where Head<K, V>: UnsafeUnpin, C: UnsafeUnpin, A: UnsafeUnpin,

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

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

Initializes a with the given initializer. Read more
Source§

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

Dereferences the given pointer. Read more
Source§

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

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

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

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

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

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more