Skip to main content

LearnedSet

Struct LearnedSet 

Source
pub struct LearnedSet<K: Key> { /* private fields */ }
Expand description

A sorted set backed by a learned index.

This is a thin wrapper around LearnedMap<K, ()>.

All operations take &self and are safe to call from multiple threads.

Implementations§

Source§

impl<K: Key> LearnedSet<K>

Source

pub fn new() -> Self

Create a new empty set.

Source

pub fn with_config(config: Config) -> Self

Create a new set with the given configuration.

Source

pub fn bulk_load(keys: &[K]) -> Result<Self>

Create a set from sorted keys, deduplicating any repeated keys.

Keys must be in ascending order but duplicates are allowed and will be silently removed (sets are idempotent by definition).

§Errors

Returns an error if keys is empty (after dedup) or not sorted.

Source

pub fn guard(&self) -> Guard

Acquire an epoch guard.

Source

pub fn pin(&self) -> SetRef<'_, K>

Pin the current epoch and return a SetRef convenience handle.

Source

pub fn insert(&self, key: K, guard: &Guard) -> bool

Insert a key. Returns true if the key was newly inserted.

Source

pub fn remove(&self, key: &K, guard: &Guard) -> bool

Remove a key. Returns true if the key was present.

Source

pub fn contains(&self, key: &K, guard: &Guard) -> bool

Check whether the set contains a key.

Source

pub fn len(&self) -> usize

Return the approximate number of elements in the set.

See LearnedMap::len for details on relaxed-atomic staleness under concurrency.

Source

pub fn is_empty(&self) -> bool

Return true if the set is empty.

Subject to the same relaxed-atomic staleness as len.

Source

pub fn range<'g, R: RangeBounds<K>>( &self, range: R, guard: &'g Guard, ) -> impl Iterator<Item = &'g K>

Return an iterator over keys within the given range, in ascending order.

Source

pub fn first<'g>(&self, guard: &'g Guard) -> Option<&'g K>

Return the first (minimum) key.

Source

pub fn last<'g>(&self, guard: &'g Guard) -> Option<&'g K>

Return the last (maximum) key.

Trait Implementations§

Source§

impl<K: Debug + Key> Debug for LearnedSet<K>

Source§

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

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

impl<K: Key> Default for LearnedSet<K>

Source§

fn default() -> Self

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

impl<K: Key> Extend<K> for LearnedSet<K>

Source§

fn extend<I: IntoIterator<Item = K>>(&mut self, iter: I)

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

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<K: Key> FromIterator<K> for LearnedSet<K>

Source§

fn from_iter<I: IntoIterator<Item = K>>(iter: I) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl<K> !Freeze for LearnedSet<K>

§

impl<K> !RefUnwindSafe for LearnedSet<K>

§

impl<K> Send for LearnedSet<K>

§

impl<K> Sync for LearnedSet<K>

§

impl<K> Unpin for LearnedSet<K>

§

impl<K> UnsafeUnpin for LearnedSet<K>

§

impl<K> !UnwindSafe for LearnedSet<K>

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> 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, 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.