haar_lib/algebra/
update_sum.rs

1//! Range Update Range Sum
2pub use crate::algebra::{action::Action, first_last::Last, sum::Sum, traits::*};
3use std::fmt::Debug;
4use std::marker::PhantomData;
5use std::ops::Mul;
6
7/// Range Update Range Sum用の代数的構造
8#[derive(Copy, Clone, Default, Debug, PartialEq, Eq)]
9pub struct UpdateSum<T>(PhantomData<T>);
10
11impl<T> Action for UpdateSum<T>
12where
13    Sum<T>: Monoid,
14    Last<T>: Monoid,
15    T: Mul<Output = T> + TryFrom<usize, Error: Debug>,
16{
17    type Output = Sum<T>;
18    type Lazy = Last<T>;
19
20    fn convert(value: Self::Output, lazy: Self::Lazy, len: usize) -> Self::Output {
21        match lazy.0 {
22            Some(lazy) => Sum(lazy * T::try_from(len).unwrap()),
23            _ => value,
24        }
25    }
26}