pub struct SparseTable<T, F: Fn(T, T) -> T> { /* private fields */ }Expand description
Sparse Table for idempotent, associative operations on a static array.
Implementations§
Source§impl<T: Clone + Copy, F: Fn(T, T) -> T + Copy> SparseTable<T, F>
impl<T: Clone + Copy, F: Fn(T, T) -> T + Copy> SparseTable<T, F>
Sourcepub fn new(a: &[T], op: F) -> Self
pub fn new(a: &[T], op: F) -> Self
Build a Sparse Table from a slice using the given operation op,
which must be associative and idempotent.
Sourcepub fn query(&self, l: usize, r: usize) -> Option<T>
pub fn query(&self, l: usize, r: usize) -> Option<T>
Query op(a[l], a[l+1], ..., a[r-1]) over the half-open range
[l, r). Returns None if the range is empty or out of bounds.
Two windows of length 2^k, where k = log2(r - l), exactly
cover [l, r). Since op is idempotent, overlapping them is
safe.
Auto Trait Implementations§
impl<T, F> Freeze for SparseTable<T, F>where
F: Freeze,
impl<T, F> RefUnwindSafe for SparseTable<T, F>where
F: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, F> Send for SparseTable<T, F>
impl<T, F> Sync for SparseTable<T, F>
impl<T, F> Unpin for SparseTable<T, F>
impl<T, F> UnsafeUnpin for SparseTable<T, F>where
F: UnsafeUnpin,
impl<T, F> UnwindSafe for SparseTable<T, F>where
F: UnwindSafe,
T: UnwindSafe,
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