pub struct SkipList<K, V, C = BasicComparator, A: SkiplistAllocator = TursoAllocator> { /* private fields */ }Expand description
A lock-free skip list.
Implementations§
Source§impl<K, V, A: SkiplistAllocator> SkipList<K, V, BasicComparator, A>
impl<K, V, A: SkiplistAllocator> SkipList<K, V, BasicComparator, A>
Source§impl<K, V, C> SkipList<K, V, C>
impl<K, V, C> SkipList<K, V, C>
Sourcepub fn with_comparator(collector: Collector, comparator: C) -> Self
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>
impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>
Sourcepub fn with_comparator_in(collector: Collector, comparator: C, alloc: A) -> Self
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§impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>where
C: Comparator<K>,
impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>where
C: Comparator<K>,
Sourcepub fn front<'a: 'g, 'g>(
&'a self,
guard: &'g Guard,
) -> Option<Entry<'a, 'g, K, V, C, A>>
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.
Sourcepub fn back<'a: 'g, 'g>(
&'a self,
guard: &'g Guard,
) -> Option<Entry<'a, 'g, K, V, C, A>>
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.
Sourcepub fn contains_key<Q>(&self, key: &Q, guard: &Guard) -> boolwhere
C: Comparator<K, Q>,
Q: ?Sized,
pub fn contains_key<Q>(&self, key: &Q, guard: &Guard) -> boolwhere
C: Comparator<K, Q>,
Q: ?Sized,
Returns true if the map contains a value for the specified key.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub 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,
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.
Sourcepub fn get_or_insert(
&self,
key: K,
value: V,
guard: &Guard,
) -> RefEntry<'_, K, V, C, A>
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.
Sourcepub fn try_get_or_insert(
&self,
key: K,
value: V,
guard: &Guard,
) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>
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.
Sourcepub fn get_or_insert_with<F>(
&self,
key: K,
value: F,
guard: &Guard,
) -> RefEntry<'_, K, V, C, A>where
F: FnOnce() -> V,
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
Sourcepub 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,
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.
Sourcepub fn iter<'a: 'g, 'g>(&'a self, guard: &'g Guard) -> Iter<'a, 'g, K, V, C, A> ⓘ
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.
Sourcepub fn ref_iter(&self) -> RefIter<'_, K, V, C, A>
pub fn ref_iter(&self) -> RefIter<'_, K, V, C, A>
Returns an iterator over all entries in the skip list.
Sourcepub fn range<'a: 'g, 'g, Q, R>(
&'a self,
range: R,
guard: &'g Guard,
) -> Range<'a, 'g, Q, R, K, V, C, A> ⓘ
pub fn range<'a: 'g, 'g, Q, R>( &'a self, range: R, guard: &'g Guard, ) -> Range<'a, 'g, Q, R, K, V, C, A> ⓘ
Returns an iterator over a subset of entries in the skip list.
Source§impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>
impl<K, V, C, A: SkiplistAllocator> SkipList<K, V, C, A>
Sourcepub fn insert(
&self,
key: K,
value: V,
guard: &Guard,
) -> RefEntry<'_, K, V, C, A>
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.
Sourcepub fn try_insert(
&self,
key: K,
value: V,
guard: &Guard,
) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>
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.
Sourcepub fn compare_insert<F>(
&self,
key: K,
value: V,
compare_fn: F,
guard: &Guard,
) -> RefEntry<'_, K, V, C, A>
pub fn compare_insert<F>( &self, key: K, value: V, compare_fn: F, 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 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.
Sourcepub fn try_compare_insert<F>(
&self,
key: K,
value: V,
compare_fn: F,
guard: &Guard,
) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>
pub fn try_compare_insert<F>( &self, key: K, value: V, compare_fn: F, guard: &Guard, ) -> Result<RefEntry<'_, K, V, C, A>, TryReserveError>
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.
Sourcepub fn remove<Q>(
&self,
key: &Q,
guard: &Guard,
) -> Option<RefEntry<'_, K, V, C, A>>where
C: Comparator<K, Q>,
Q: ?Sized,
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.
Sourcepub fn pop_front(&self, guard: &Guard) -> Option<RefEntry<'_, K, V, C, A>>
pub fn pop_front(&self, guard: &Guard) -> Option<RefEntry<'_, K, V, C, A>>
Removes an entry from the front of the skip list.
Trait Implementations§
Source§impl<K, V, C, A: SkiplistAllocator> Debug for SkipList<K, V, C, A>
impl<K, V, C, A: SkiplistAllocator> Debug for SkipList<K, V, C, A>
Source§impl<K, V, C, A: SkiplistAllocator> Drop for SkipList<K, V, C, A>
impl<K, V, C, A: SkiplistAllocator> Drop for SkipList<K, V, C, A>
Source§impl<K, V, C, A: SkiplistAllocator> IntoIterator for SkipList<K, V, C, A>
impl<K, V, C, A: SkiplistAllocator> IntoIterator for SkipList<K, V, C, A>
impl<K: Send + Sync, V: Send + Sync, C: Send + Sync, A: SkiplistAllocator> Send for SkipList<K, V, C, A>
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>
impl<K, V, C, A> UnsafeUnpin for SkipList<K, V, C, A>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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