pub struct PrefixSum { /* private fields */ }Expand description
Prefix-sum array over a slice of integers.
Supports O(1) range-sum queries after O(n) construction.
§Example
let ps = PrefixSum::build(&[1, 2, 3, 4, 5]);
assert_eq!(ps.range_sum(1, 3), 9); // 2 + 3 + 4Implementations§
Source§impl PrefixSum
impl PrefixSum
Sourcepub fn build(data: &[i64]) -> Self
pub fn build(data: &[i64]) -> Self
Build a prefix-sum structure from a slice.
prefix[0] = 0, prefix[i+1] = prefix[i] + data[i].
Auto Trait Implementations§
impl Freeze for PrefixSum
impl RefUnwindSafe for PrefixSum
impl Send for PrefixSum
impl Sync for PrefixSum
impl Unpin for PrefixSum
impl UnsafeUnpin for PrefixSum
impl UnwindSafe for PrefixSum
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