Dynamic

Struct Dynamic 

Source
pub struct Dynamic<T: Indexable + Ord>
where T::Key: Ord,
{ /* private fields */ }
Expand description

A dynamic PGM-Index that supports insertions and deletions.

This index owns its data and maintains insert/delete buffers that are periodically merged into the main index. When the buffers exceed a threshold, the index is automatically rebuilt.

§Example

use pgm_extra::index::owned::Dynamic;

let mut index: Dynamic<u64> = Dynamic::new(16, 4);

index.insert(5);
index.insert(3);
index.insert(7);

assert!(index.contains(&3));
assert!(index.contains(&5));
assert!(!index.contains(&4));

Implementations§

Source§

impl<T: Indexable + Ord + Copy> Dynamic<T>
where T::Key: Ord,

Source

pub fn new(epsilon: usize, epsilon_recursive: usize) -> Self

Create a new empty dynamic index.

Source

pub fn from_sorted( data: Vec<T>, epsilon: usize, epsilon_recursive: usize, ) -> Result<Self, Error>

Create a dynamic index from pre-sorted data.

Source

pub fn with_rebuild_threshold(self, threshold: usize) -> Self

Set the threshold for automatic rebuilding.

Source

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

Insert a value into the index.

Source

pub fn remove(&mut self, value: &T) -> bool

Remove a value from the index.

Source

pub fn contains(&self, value: &T) -> bool

Check if a value exists in the index.

Source

pub fn lower_bound(&self, value: &T) -> Option<T>

Find the smallest value >= the given value.

Source

pub fn len(&self) -> usize

Get the number of elements in the index.

Source

pub fn is_empty(&self) -> bool

Source

pub fn pending_operations(&self) -> usize

Get the number of pending operations in buffers.

Source

pub fn force_rebuild(&mut self)

Force an immediate rebuild of the index.

Source

pub fn iter(&self) -> impl Iterator<Item = T> + '_

Iterate over all values in sorted order.

Source

pub fn range<'a, R>(&'a self, range: R) -> impl Iterator<Item = T> + 'a
where R: RangeBounds<T> + Clone + 'a,

Iterate over values in the given range.

Source

pub fn size_in_bytes(&self) -> usize

Approximate memory usage in bytes.

Trait Implementations§

Source§

impl<T: Indexable + Ord + Debug> Debug for Dynamic<T>
where T::Key: Ord,

Source§

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

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

impl<'de, T> Deserialize<'de> for Dynamic<T>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<T: Indexable + Ord + Copy> Extend<T> for Dynamic<T>
where T::Key: Ord,

Source§

fn extend<I: IntoIterator<Item = T>>(&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<T> Serialize for Dynamic<T>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Dynamic<T>

§

impl<T> RefUnwindSafe for Dynamic<T>

§

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

§

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

§

impl<T> Unpin for Dynamic<T>
where T: Unpin, <T as Indexable>::Key: Unpin,

§

impl<T> UnwindSafe for Dynamic<T>

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,