Struct seg_tree::segment_tree::PersistentSegmentTree
source · [−]pub struct PersistentSegmentTree<T: PersistentNode> { /* private fields */ }
Expand description
Persistent segment tree, it saves every version of itself, it has range queries and point updates.
It uses O(n+q*log(n))
space, where q
is the amount of updates, and assuming that each node uses O(1)
space.
Implementations
sourceimpl<T> PersistentSegmentTree<T> where
T: PersistentNode + Clone,
impl<T> PersistentSegmentTree<T> where
T: PersistentNode + Clone,
sourcepub fn build(values: &[T]) -> Self
pub fn build(values: &[T]) -> Self
Builds persistent segment tree from slice, each element of the slice will correspond to a leaf of the segment tree.
It has time complexity of O(n*log(n))
, assuming that combine has constant time complexity.
sourcepub fn query(&self, version: usize, left: usize, right: usize) -> Option<T>
pub fn query(&self, version: usize, left: usize, right: usize) -> Option<T>
Returns the result from the range [left,right] from the version of the segment tree.
It returns None if and only if range is empty.
It will panic if left or right are not in [0,n), or if version is not in [0,versions).
It has time complexity of O(log(n))
, assuming that combine has constant time complexity.
sourcepub fn update(&mut self, version: usize, p: usize, value: <T as Node>::Value)
pub fn update(&mut self, version: usize, p: usize, value: <T as Node>::Value)
Creates a new segment tree version from version were the p-th element of the segment tree to value T and update the segment tree correspondingly.
It will panic if p is not in [0,n), or if version is not in [0,versions).
It has time complexity of O(log(n))
, assuming that combine has constant time complexity.
Auto Trait Implementations
impl<T> RefUnwindSafe for PersistentSegmentTree<T> where
T: RefUnwindSafe,
impl<T> Send for PersistentSegmentTree<T> where
T: Send,
impl<T> Sync for PersistentSegmentTree<T> where
T: Sync,
impl<T> Unpin for PersistentSegmentTree<T> where
T: Unpin,
impl<T> UnwindSafe for PersistentSegmentTree<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more