Struct mz_persist_client::internal::merge::MergeTree
source · pub struct MergeTree<T> {
pub(crate) max_len: usize,
pub(crate) levels: Vec<Vec<T>>,
merge_fn: Box<dyn Fn(Vec<T>) -> T + Sync + Send>,
}
Expand description
A merge tree.
Invariants and guarantees:
- This structure preserves the order in which elements are
push
ed. - Merging also preserves order: only adjacent elements will be merged together, and the result will have the same place in the ordering as the input did.
- The tree will store at most
O(K log N)
elements at once, whereK
is the provided max len andN
is the number of elements pushed. finish
will return at mostK
elements.- The “depth” of the merge tree - the number of merges any particular element may undergo -
is
O(log N)
.
Fields§
§max_len: usize
§levels: Vec<Vec<T>>
§merge_fn: Box<dyn Fn(Vec<T>) -> T + Sync + Send>
Implementations§
source§impl<T> MergeTree<T>
impl<T> MergeTree<T>
sourcepub fn new(
max_len: usize,
merge_fn: impl Fn(Vec<T>) -> T + Send + Sync + 'static,
) -> Self
pub fn new( max_len: usize, merge_fn: impl Fn(Vec<T>) -> T + Send + Sync + 'static, ) -> Self
Create a new merge tree. max_len
limits both the number of parts to keep at each level of
the tree, and the number of parts that Self::finish
will return… and if we exceed that
limit, the provided merge_fn
is used to combine adjacent elements together.
sourcepub fn iter(&self) -> impl Iterator<Item = &T> + DoubleEndedIterator
pub fn iter(&self) -> impl Iterator<Item = &T> + DoubleEndedIterator
Iterate over (references to) the parts in this tree in first-to-latest order.
sourcepub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> + DoubleEndedIterator
pub fn iter_mut(&mut self) -> impl Iterator<Item = &mut T> + DoubleEndedIterator
Iterate over (mutable references to) the parts in this tree in first-to-latest order.
sourcepub fn push(&mut self, part: T)
pub fn push(&mut self, part: T)
Push a new part onto the end of this tree, possibly triggering a merge.
sourcepub fn finish(self) -> Vec<T>
pub fn finish(self) -> Vec<T>
Return the contents of this merge tree, flattened into at most max_len
parts.
pub(crate) fn assert_invariants(&self)
Trait Implementations§
Auto Trait Implementations§
impl<T> Freeze for MergeTree<T>
impl<T> !RefUnwindSafe for MergeTree<T>
impl<T> Send for MergeTree<T>where
T: Send,
impl<T> Sync for MergeTree<T>where
T: Sync,
impl<T> Unpin for MergeTree<T>where
T: Unpin,
impl<T> !UnwindSafe for MergeTree<T>
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
Mutably borrows from an owned value. Read more
source§impl<T> FutureExt for T
impl<T> FutureExt for T
source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T
in a tonic::Request
Creates a shared type from an unshared type.
source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
impl<P, R> ProtoType<R> for Pwhere
R: RustType<P>,
source§fn into_rust(self) -> Result<R, TryFromProtoError>
fn into_rust(self) -> Result<R, TryFromProtoError>
See
RustType::from_proto
.source§fn from_rust(rust: &R) -> P
fn from_rust(rust: &R) -> P
See
RustType::into_proto
.source§impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
impl<'a, S, T> Semigroup<&'a S> for Twhere
T: Semigroup<S>,
source§fn plus_equals(&mut self, rhs: &&'a S)
fn plus_equals(&mut self, rhs: &&'a S)
The method of
std::ops::AddAssign
, for types that do not implement AddAssign
.