pub struct SkipSet<T, C = BasicComparator, A: SkiplistAllocator = TursoAllocator> { /* private fields */ }Expand description
A set based on a lock-free skip list.
This is an alternative to BTreeSet which supports
concurrent access across multiple threads.
A custom comparator may be provided, causing all
elements to be ordered by the comparison function used
instead of the standard Ord impl. See Comparator.
Implementations§
Source§impl<T, A: SkiplistAllocator> SkipSet<T, BasicComparator, A>
impl<T, A: SkiplistAllocator> SkipSet<T, BasicComparator, A>
Source§impl<T, C> SkipSet<T, C>
impl<T, C> SkipSet<T, C>
Sourcepub fn with_comparator(comparator: C) -> Self
pub fn with_comparator(comparator: C) -> Self
Returns a new, empty set with the given comparator.
§Example
use turso_core::skiplist::{SkipSet, comparator::BasicComparator};
let set: SkipSet<i32> = SkipSet::with_comparator(BasicComparator);Source§impl<T, C, A: SkiplistAllocator> SkipSet<T, C, A>
impl<T, C, A: SkiplistAllocator> SkipSet<T, C, A>
Sourcepub fn with_comparator_in(comparator: C, alloc: A) -> Self
pub fn with_comparator_in(comparator: C, alloc: A) -> Self
Returns a new, empty set with the given comparator that allocates its
nodes in alloc.
§Example
use turso_core::alloc::TursoAllocator;
use turso_core::skiplist::{SkipSet, comparator::BasicComparator};
let set: SkipSet<i32, _, TursoAllocator> =
SkipSet::with_comparator_in(BasicComparator, TursoAllocator);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the set is empty.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
assert!(set.is_empty());
set.insert(1);
assert!(!set.is_empty());Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of entries in the set.
If the set is being concurrently modified, consider the returned number just an approximation without any guarantees.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
assert_eq!(set.len(), 0);
set.insert(1);
assert_eq!(set.len(), 1);Source§impl<T, C, A: SkiplistAllocator> SkipSet<T, C, A>where
C: Comparator<T>,
impl<T, C, A: SkiplistAllocator> SkipSet<T, C, A>where
C: Comparator<T>,
Sourcepub fn front(&self) -> Option<Entry<'_, T, C, A>>
pub fn front(&self) -> Option<Entry<'_, T, C, A>>
Returns the entry with the smallest key.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(1);
assert_eq!(*set.front().unwrap(), 1);
set.insert(2);
assert_eq!(*set.front().unwrap(), 1);Sourcepub fn back(&self) -> Option<Entry<'_, T, C, A>>
pub fn back(&self) -> Option<Entry<'_, T, C, A>>
Returns the entry with the largest key.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(1);
assert_eq!(*set.back().unwrap(), 1);
set.insert(2);
assert_eq!(*set.back().unwrap(), 2);Sourcepub fn contains<Q>(&self, key: &Q) -> boolwhere
C: Comparator<T, Q>,
Q: ?Sized,
pub fn contains<Q>(&self, key: &Q) -> boolwhere
C: Comparator<T, Q>,
Q: ?Sized,
Returns true if the set contains a value for the specified key.
§Example
use turso_core::skiplist::SkipSet;
let set: SkipSet<_> = (1..=3).collect();
assert!(set.contains(&1));
assert!(!set.contains(&4));Sourcepub fn get<Q>(&self, key: &Q) -> Option<Entry<'_, T, C, A>>where
C: Comparator<T, Q>,
Q: ?Sized,
pub fn get<Q>(&self, key: &Q) -> Option<Entry<'_, T, C, A>>where
C: Comparator<T, Q>,
Q: ?Sized,
Returns an entry with the specified key.
§Example
use turso_core::skiplist::SkipSet;
let set: SkipSet<_> = (1..=3).collect();
assert_eq!(*set.get(&3).unwrap(), 3);
assert!(set.get(&4).is_none());Sourcepub fn lower_bound<'a, Q>(
&'a self,
bound: Bound<&Q>,
) -> Option<Entry<'a, T, C, A>>where
C: Comparator<T, Q>,
Q: ?Sized,
pub fn lower_bound<'a, Q>(
&'a self,
bound: Bound<&Q>,
) -> Option<Entry<'a, T, C, A>>where
C: Comparator<T, 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.
§Example
use turso_core::skiplist::SkipSet;
use std::ops::Bound::*;
let set = SkipSet::new();
set.insert(6);
set.insert(7);
set.insert(12);
let greater_than_five = set.lower_bound(Excluded(&5)).unwrap();
assert_eq!(*greater_than_five, 6);
let greater_than_six = set.lower_bound(Excluded(&6)).unwrap();
assert_eq!(*greater_than_six, 7);
let greater_than_thirteen = set.lower_bound(Excluded(&13));
assert!(greater_than_thirteen.is_none());Sourcepub fn upper_bound<'a, Q>(
&'a self,
bound: Bound<&Q>,
) -> Option<Entry<'a, T, C, A>>where
C: Comparator<T, Q>,
Q: ?Sized,
pub fn upper_bound<'a, Q>(
&'a self,
bound: Bound<&Q>,
) -> Option<Entry<'a, T, C, A>>where
C: Comparator<T, 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.
§Example
use turso_core::skiplist::SkipSet;
use std::ops::Bound::*;
let set = SkipSet::new();
set.insert(6);
set.insert(7);
set.insert(12);
let less_than_eight = set.upper_bound(Excluded(&8)).unwrap();
assert_eq!(*less_than_eight, 7);
let less_than_six = set.upper_bound(Excluded(&6));
assert!(less_than_six.is_none());Sourcepub fn get_or_insert(&self, key: T) -> Entry<'_, T, C, A>
pub fn get_or_insert(&self, key: T) -> Entry<'_, T, C, A>
Finds an entry with the specified key, or inserts a new key-value pair if none exist.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
let entry = set.get_or_insert(2);
assert_eq!(*entry, 2);Sourcepub fn try_get_or_insert(
&self,
key: T,
) -> Result<Entry<'_, T, C, A>, TryReserveError>
pub fn try_get_or_insert( &self, key: T, ) -> Result<Entry<'_, T, C, A>, TryReserveError>
Fallible version of get_or_insert: returns an error instead of
aborting the process when node allocation fails.
On error the set is unchanged and key is dropped.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
let entry = set.try_get_or_insert(2).unwrap();
assert_eq!(*entry, 2);Sourcepub fn iter(&self) -> Iter<'_, T, C, A> ⓘ
pub fn iter(&self) -> Iter<'_, T, C, A> ⓘ
Returns an iterator over all entries in the set.
§Examples
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(6);
set.insert(7);
set.insert(12);
let mut set_iter = set.iter();
assert_eq!(*set_iter.next().unwrap(), 6);
assert_eq!(*set_iter.next().unwrap(), 7);
assert_eq!(*set_iter.next().unwrap(), 12);
assert!(set_iter.next().is_none());Sourcepub fn range<Q, R>(&self, range: R) -> Range<'_, Q, R, T, C, A> ⓘ
pub fn range<Q, R>(&self, range: R) -> Range<'_, Q, R, T, C, A> ⓘ
Returns an iterator over a subset of entries in the set.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(6);
set.insert(7);
set.insert(12);
let mut set_range = set.range(5..=8);
assert_eq!(*set_range.next().unwrap(), 6);
assert_eq!(*set_range.next().unwrap(), 7);
assert!(set_range.next().is_none());Source§impl<T, C, A: SkiplistAllocator> SkipSet<T, C, A>where
C: Comparator<T>,
T: Send + 'static,
impl<T, C, A: SkiplistAllocator> SkipSet<T, C, A>where
C: Comparator<T>,
T: Send + 'static,
Sourcepub fn insert(&self, key: T) -> Entry<'_, T, C, A>
pub fn insert(&self, key: T) -> Entry<'_, T, C, A>
Inserts a key-value pair into the set and returns the new entry.
If there is an existing entry with this key, it will be removed before inserting the new one.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(2);
assert_eq!(*set.get(&2).unwrap(), 2);Sourcepub fn try_insert(&self, key: T) -> Result<Entry<'_, T, C, A>, TryReserveError>
pub fn try_insert(&self, key: T) -> Result<Entry<'_, T, C, A>, TryReserveError>
Sourcepub fn remove<Q>(&self, key: &Q) -> Option<Entry<'_, T, C, A>>where
C: Comparator<T, Q>,
Q: ?Sized,
pub fn remove<Q>(&self, key: &Q) -> Option<Entry<'_, T, C, A>>where
C: Comparator<T, Q>,
Q: ?Sized,
Removes an entry with the specified key from the set and returns it.
The value will not actually be dropped until all references to it have gone out of scope.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(2);
assert_eq!(*set.remove(&2).unwrap(), 2);
assert!(set.remove(&2).is_none());Sourcepub fn pop_front(&self) -> Option<Entry<'_, T, C, A>>
pub fn pop_front(&self) -> Option<Entry<'_, T, C, A>>
Removes an entry from the front of the set. Returns the removed entry.
The value will not actually be dropped until all references to it have gone out of scope.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(1);
set.insert(2);
assert_eq!(*set.pop_front().unwrap(), 1);
assert_eq!(*set.pop_front().unwrap(), 2);
// All entries have been removed now.
assert!(set.is_empty());Sourcepub fn pop_back(&self) -> Option<Entry<'_, T, C, A>>
pub fn pop_back(&self) -> Option<Entry<'_, T, C, A>>
Removes an entry from the back of the set. Returns the removed entry.
The value will not actually be dropped until all references to it have gone out of scope.
§Example
use turso_core::skiplist::SkipSet;
let set = SkipSet::new();
set.insert(1);
set.insert(2);
assert_eq!(*set.pop_back().unwrap(), 2);
assert_eq!(*set.pop_back().unwrap(), 1);
// All entries have been removed now.
assert!(set.is_empty());Trait Implementations§
Source§impl<T, C, A: SkiplistAllocator> Debug for SkipSet<T, C, A>where
C: Comparator<T>,
T: Debug,
impl<T, C, A: SkiplistAllocator> Debug for SkipSet<T, C, A>where
C: Comparator<T>,
T: Debug,
Source§impl<T, C> FromIterator<T> for SkipSet<T, C>where
C: Comparator<T> + Default,
impl<T, C> FromIterator<T> for SkipSet<T, C>where
C: Comparator<T> + Default,
Source§fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
fn from_iter<I>(iter: I) -> Selfwhere
I: IntoIterator<Item = T>,
Source§impl<T, C, A: SkiplistAllocator> IntoIterator for SkipSet<T, C, A>
impl<T, C, A: SkiplistAllocator> IntoIterator for SkipSet<T, C, A>
Source§impl<'a, T, C, A: SkiplistAllocator> IntoIterator for &'a SkipSet<T, C, A>where
C: Comparator<T>,
impl<'a, T, C, A: SkiplistAllocator> IntoIterator for &'a SkipSet<T, C, A>where
C: Comparator<T>,
Auto Trait Implementations§
impl<T, C = BasicComparator, A = TursoAllocator> !Freeze for SkipSet<T, C, A>
impl<T, C = BasicComparator, A = TursoAllocator> !RefUnwindSafe for SkipSet<T, C, A>
impl<T, C = BasicComparator, A = TursoAllocator> !UnwindSafe for SkipSet<T, C, A>
impl<T, C, A> Send for SkipSet<T, C, A>
impl<T, C, A> Sync for SkipSet<T, C, A>
impl<T, C, A> Unpin for SkipSet<T, C, A>
impl<T, C, A> UnsafeUnpin for SkipSet<T, 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 moreSource§impl<'a, I> MultiOps<&'a RoaringBitmap> for Iwhere
I: IntoIterator<Item = &'a RoaringBitmap>,
impl<'a, I> MultiOps<&'a RoaringBitmap> for Iwhere
I: IntoIterator<Item = &'a RoaringBitmap>,
Source§type Output = RoaringBitmap
type Output = RoaringBitmap
Source§fn intersection(self) -> <I as MultiOps<&'a RoaringBitmap>>::Output
fn intersection(self) -> <I as MultiOps<&'a RoaringBitmap>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<&'a RoaringBitmap>>::Output
fn difference(self) -> <I as MultiOps<&'a RoaringBitmap>>::Output
difference between all elements.Source§fn symmetric_difference(self) -> <I as MultiOps<&'a RoaringBitmap>>::Output
fn symmetric_difference(self) -> <I as MultiOps<&'a RoaringBitmap>>::Output
symmetric difference between all elements.Source§impl<'a, I> MultiOps<&'a RoaringTreemap> for Iwhere
I: IntoIterator<Item = &'a RoaringTreemap>,
impl<'a, I> MultiOps<&'a RoaringTreemap> for Iwhere
I: IntoIterator<Item = &'a RoaringTreemap>,
Source§type Output = RoaringTreemap
type Output = RoaringTreemap
Source§fn intersection(self) -> <I as MultiOps<&'a RoaringTreemap>>::Output
fn intersection(self) -> <I as MultiOps<&'a RoaringTreemap>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<&'a RoaringTreemap>>::Output
fn difference(self) -> <I as MultiOps<&'a RoaringTreemap>>::Output
difference between all elements.Source§fn symmetric_difference(self) -> <I as MultiOps<&'a RoaringTreemap>>::Output
fn symmetric_difference(self) -> <I as MultiOps<&'a RoaringTreemap>>::Output
symmetric difference between all elements.Source§impl<'a, I, E> MultiOps<Result<&'a RoaringBitmap, E>> for I
impl<'a, I, E> MultiOps<Result<&'a RoaringBitmap, E>> for I
Source§type Output = Result<RoaringBitmap, E>
type Output = Result<RoaringBitmap, E>
Source§fn union(self) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
fn union(self) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
union between all elements.Source§fn intersection(self) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
fn intersection(self) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
fn difference(self) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
difference between all elements.Source§fn symmetric_difference(
self,
) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
fn symmetric_difference( self, ) -> <I as MultiOps<Result<&'a RoaringBitmap, E>>>::Output
symmetric difference between all elements.Source§impl<'a, I, E> MultiOps<Result<&'a RoaringTreemap, E>> for I
impl<'a, I, E> MultiOps<Result<&'a RoaringTreemap, E>> for I
Source§type Output = Result<RoaringTreemap, E>
type Output = Result<RoaringTreemap, E>
Source§fn union(self) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
fn union(self) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
union between all elements.Source§fn intersection(self) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
fn intersection(self) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
fn difference(self) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
difference between all elements.Source§fn symmetric_difference(
self,
) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
fn symmetric_difference( self, ) -> <I as MultiOps<Result<&'a RoaringTreemap, E>>>::Output
symmetric difference between all elements.Source§impl<I, E> MultiOps<Result<RoaringBitmap, E>> for I
impl<I, E> MultiOps<Result<RoaringBitmap, E>> for I
Source§type Output = Result<RoaringBitmap, E>
type Output = Result<RoaringBitmap, E>
Source§fn union(self) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
fn union(self) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
union between all elements.Source§fn intersection(self) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
fn intersection(self) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
fn difference(self) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
difference between all elements.Source§fn symmetric_difference(
self,
) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
fn symmetric_difference( self, ) -> <I as MultiOps<Result<RoaringBitmap, E>>>::Output
symmetric difference between all elements.Source§impl<I, E> MultiOps<Result<RoaringTreemap, E>> for I
impl<I, E> MultiOps<Result<RoaringTreemap, E>> for I
Source§type Output = Result<RoaringTreemap, E>
type Output = Result<RoaringTreemap, E>
Source§fn union(self) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
fn union(self) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
union between all elements.Source§fn intersection(self) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
fn intersection(self) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
fn difference(self) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
difference between all elements.Source§fn symmetric_difference(
self,
) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
fn symmetric_difference( self, ) -> <I as MultiOps<Result<RoaringTreemap, E>>>::Output
symmetric difference between all elements.Source§impl<I> MultiOps<RoaringBitmap> for Iwhere
I: IntoIterator<Item = RoaringBitmap>,
impl<I> MultiOps<RoaringBitmap> for Iwhere
I: IntoIterator<Item = RoaringBitmap>,
Source§type Output = RoaringBitmap
type Output = RoaringBitmap
Source§fn intersection(self) -> <I as MultiOps<RoaringBitmap>>::Output
fn intersection(self) -> <I as MultiOps<RoaringBitmap>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<RoaringBitmap>>::Output
fn difference(self) -> <I as MultiOps<RoaringBitmap>>::Output
difference between all elements.Source§fn symmetric_difference(self) -> <I as MultiOps<RoaringBitmap>>::Output
fn symmetric_difference(self) -> <I as MultiOps<RoaringBitmap>>::Output
symmetric difference between all elements.Source§impl<I> MultiOps<RoaringTreemap> for Iwhere
I: IntoIterator<Item = RoaringTreemap>,
impl<I> MultiOps<RoaringTreemap> for Iwhere
I: IntoIterator<Item = RoaringTreemap>,
Source§type Output = RoaringTreemap
type Output = RoaringTreemap
Source§fn intersection(self) -> <I as MultiOps<RoaringTreemap>>::Output
fn intersection(self) -> <I as MultiOps<RoaringTreemap>>::Output
intersection between all elements.Source§fn difference(self) -> <I as MultiOps<RoaringTreemap>>::Output
fn difference(self) -> <I as MultiOps<RoaringTreemap>>::Output
difference between all elements.Source§fn symmetric_difference(self) -> <I as MultiOps<RoaringTreemap>>::Output
fn symmetric_difference(self) -> <I as MultiOps<RoaringTreemap>>::Output
symmetric difference between all elements.