LazySegTreeSpec

Trait LazySegTreeSpec 

Source
pub trait LazySegTreeSpec {
    type T: Clone;
    type U: Clone;

    const ID: Self::T;

    // Required methods
    fn op_on_data(d1: &Self::T, d2: &Self::T) -> Self::T;
    fn op_on_update(u1: &Self::U, u2: &Self::U) -> Self::U;
    fn op_update_on_data(u: &Self::U, d: &Self::T, size: usize) -> Self::T;

    // Provided method
    fn op_on_update_option(
        existing_tag: &Option<Self::U>,
        new_tag: &Self::U,
    ) -> Option<Self::U> { ... }
}
Expand description

Specification trait for LazySegTree.

Implement this trait to define the concrete behavior of the tree:

  • T: data stored in nodes (the aggregate type),
  • U: lazy-update type (the tag type),
  • ID: identity element for T.

Required operations:

  • op_on_data — combine two Ts into one (e.g., sum or min),
  • op_on_update — compose two updates U into a single update,
  • op_update_on_data — apply an update U to T representing size leaves.

Required Associated Constants§

Source

const ID: Self::T

Identity element for T.

Required Associated Types§

Required Methods§

Source

fn op_on_data(d1: &Self::T, d2: &Self::T) -> Self::T

Combine two child values into a parent value.

Source

fn op_on_update(u1: &Self::U, u2: &Self::U) -> Self::U

Compose two updates. If update a is applied before b, then the composed update should be op_on_update(a, b) (document the intended order in non-commutative cases).

Source

fn op_update_on_data(u: &Self::U, d: &Self::T, size: usize) -> Self::T

Apply an update u to a node’s stored aggregate d which represents size leaves. For example, for range-add + range-sum: op_update_on_data(u, d, size) = d + u * size.

Provided Methods§

Source

fn op_on_update_option( existing_tag: &Option<Self::U>, new_tag: &Self::U, ) -> Option<Self::U>

Helper to combine an existing optional tag with a new tag.

Default behavior: if there is an existing tag, compose them using op_on_update; otherwise, install new_tag.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T> LazySegTreeSpec for LazySegTreeAddMaxSpec<T>
where T: Clone + Add<Output = T> + ConstLowerBound + Ord,

Source§

const ID: Self::T = <T as ConstLowerBound>::MIN

Source§

type T = T

Source§

type U = T

Source§

impl<T> LazySegTreeSpec for LazySegTreeAddMinSpec<T>
where T: Clone + Add<Output = T> + ConstUpperBound + Ord,

Source§

const ID: Self::T = <T as ConstUpperBound>::MAX

Source§

type T = T

Source§

type U = T

Source§

impl<T> LazySegTreeSpec for LazySegTreeAddSumSpec<T>
where T: Clone + Add<Output = T> + ConstZero,

Source§

const ID: Self::T = <T as ConstZero>::ZERO

Source§

type T = T

Source§

type U = T

Source§

impl<T> LazySegTreeSpec for LazySegTreeReplaceSumSpec<T>
where T: Clone + ConstZero + Add<Output = T> + NumCast + Mul<Output = T>,

Source§

const ID: Self::T = <T as ConstZero>::ZERO

Source§

type T = T

Source§

type U = T