LazySegTreeSpec

Trait LazySegTreeSpec 

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

    const ID: Self::T;

    // Required methods
    fn op_on_data(d1: &mut Self::T, d2: &Self::T);
    fn op_on_update(u1: &mut Self::U, u2: &Self::U);
    fn op_update_on_data(u: &Self::U, d: &mut Self::T, size: usize);
}
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.

This is the neutral element for the op_on_data operation. For sum operations, this would be 0; for min operations, this would be the maximum value.

Required Associated Types§

Source

type T: Clone

The type of elements stored and operated on in the tree nodes.

Source

type U: Clone

The type of lazy updates applied to ranges.

Required Methods§

Source

fn op_on_data(d1: &mut Self::T, d2: &Self::T)

Combine two child values into a parent value, performed in-place.

This operation must be associative. Mutates d1 to be the result of combining d1 with d2. For example, for range sum queries: *d1 += *d2.

Source

fn op_on_update(u1: &mut Self::U, u2: &Self::U)

Compose two updates, performed in-place.

If update u1 is applied before u2, then the composed update should be the result of op_on_update(u1, u2). This operation must be associative. Mutates u1 to be the result of the composition.

Source

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

Apply an update u to a node’s stored aggregate d which represents size leaves.

This operation is performed in-place and mutates d to be the result. For example, for range-add + range-sum: *d += u * size.

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