pub struct OrderTracker<Item, Gap> { /* private fields */ }
Expand description
A tracker for the order of items in a linked chunk.
This can be used to determine the absolute ordering of an item, and thus the
relative ordering of two items in a linked chunk, in an
efficient manner, thanks to OrderTracker::ordering
. Internally, it
keeps track of the relative ordering of the chunks themselves; given a
Position
in a linked chunk, the item ordering is the lexicographic
ordering of the chunk in the linked chunk, and the internal position within
the chunk. For the sake of ease, we return the absolute vector index of the
item in the linked chunk.
It requires the full links’ metadata to be provided at creation time, so that it can also give an order for an item that’s not loaded yet, in the context of lazy-loading.
Implementations§
Source§impl<Item, Gap> OrderTracker<Item, Gap>where
Item: Clone,
impl<Item, Gap> OrderTracker<Item, Gap>where
Item: Clone,
Sourcepub fn flush_updates(&mut self, inhibit: bool)
pub fn flush_updates(&mut self, inhibit: bool)
Force flushing of the updates manually.
If inhibit
is true
(which is useful in the case of lazy-loading
related updates, which shouldn’t affect the canonical, persisted
linked chunk), the updates are ignored; otherwise, they are consumed
normally.
Sourcepub fn map_updates(&mut self, updates: &[Update<Item, Gap>])
pub fn map_updates(&mut self, updates: &[Update<Item, Gap>])
Apply some out-of-band updates to the ordering tracker.
This must only be used when the updates do not affect the observed linked chunk, but would affect the fully-loaded collection.
Sourcepub fn ordering(&self, event_pos: Position) -> Option<usize>
pub fn ordering(&self, event_pos: Position) -> Option<usize>
Given an event’s position, returns its final ordering in the current state of the linked chunk as a vector.
Useful to compare the ordering of multiple events.
Precondition: the reader must be up to date, i.e.
Self::flush_updates
must have been called before this method.
Will return None
if the position doesn’t match a known chunk in the
linked chunk, or if the chunk is a gap.
Trait Implementations§
Auto Trait Implementations§
impl<Item, Gap> Freeze for OrderTracker<Item, Gap>
impl<Item, Gap> RefUnwindSafe for OrderTracker<Item, Gap>where
Item: RefUnwindSafe,
impl<Item, Gap> Send for OrderTracker<Item, Gap>
impl<Item, Gap> Sync for OrderTracker<Item, Gap>
impl<Item, Gap> Unpin for OrderTracker<Item, Gap>where
Item: Unpin,
impl<Item, Gap> UnwindSafe for OrderTracker<Item, Gap>where
Item: UnwindSafe,
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
Source§impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
impl<T, W> HasTypeWitness<W> for Twhere
W: MakeTypeWitness<Arg = T>,
T: ?Sized,
Source§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
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