Skip to content

Commit

Permalink
segtree: get_slice
Browse files Browse the repository at this point in the history
  • Loading branch information
mizar committed Apr 16, 2023
1 parent 764c814 commit 4d0dc0b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/segtree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ impl<M: Monoid> From<Vec<M::S>> for Segtree<M> {
let log = ceil_pow2(n as u32) as usize;
let size = 1 << log;
let mut d = vec![M::identity(); 2 * size];
d[size..(size + n)].clone_from_slice(&v);
d[size..][..n].clone_from_slice(&v);
let mut ret = Segtree { n, size, log, d };
for i in (1..size).rev() {
ret.update(i);
Expand Down Expand Up @@ -170,6 +170,10 @@ impl<M: Monoid> Segtree<M> {
self.d[p + self.size].clone()
}

pub fn get_slice(&self) -> &[M::S] {
&self.d[self.size..][..self.n]
}

pub fn prod<R>(&self, range: R) -> M::S
where
R: RangeBounds<usize>,
Expand Down

0 comments on commit 4d0dc0b

Please sign in to comment.