Skip to main content

Split

pub struct Split<'a, Spec>
where Spec: BstSpec,
{ left: Option<BstRoot<Spec>>, right: Option<BstRoot<Spec>>, root: &'a mut Option<BstRoot<Spec>>, }

Fields§

§left: Option<BstRoot<Spec>>§right: Option<BstRoot<Spec>>§root: &'a mut Option<BstRoot<Spec>>

Implementations§

Source§

impl<'a, Spec> Split<'a, Spec>
where Spec: BstSpec,

Source

pub fn new<Seek>( node: &'a mut Option<BstRoot<Spec>>, seeker: Seek, equal_side: EqualSide, ) -> Self
where Seek: BstSeeker<Spec = Spec>,

Examples found in repository?
crates/competitive/src/data_structure/binary_search_tree/split.rs (line 142)
138    pub fn split_mid<Seek>(&mut self, seeker: Seek, equal_side: EqualSide) -> Split<'_, Spec>
139    where
140        Seek: BstSeeker<Spec = Spec>,
141    {
142        Split::new(&mut self.mid, seeker, equal_side)
143    }
More examples
Hide additional examples
crates/competitive/src/data_structure/treap.rs (lines 417-421)
412    pub fn find_by_key<Q>(&mut self, key: &Q) -> Option<BstNodeId<TreapSpec<M, L>>>
413    where
414        M: MonoidAct<Key: Borrow<Q>>,
415        Q: Ord + ?Sized,
416    {
417        let split = Split::new(
418            &mut self.root,
419            SeekByKey::<TreapSpec<M, L>, M::Key, Q>::new(key),
420            EqualSide::Right,
421        );
422        let node = split.right()?.leftmost();
423        matches!(node.into_data().key.key.borrow().cmp(key), Ordering::Equal)
424            .then(|| self.node_id_manager.registered_node_id(node))
425            .flatten()
426    }
427
428    pub fn find_by_acc_cond<F>(&mut self, f: F) -> Option<BstNodeId<TreapSpec<M, L>>>
429    where
430        F: FnMut(&L::Agg) -> bool,
431    {
432        let split = Split::new(
433            &mut self.root,
434            SeekByAccCond::<TreapSpec<M, L>, L, F>::new(f),
435            EqualSide::Right,
436        );
437        let node = split.right()?.leftmost();
438        self.node_id_manager.registered_node_id(node)
439    }
440
441    pub fn find_by_racc_cond<F>(&mut self, f: F) -> Option<BstNodeId<TreapSpec<M, L>>>
442    where
443        F: FnMut(&L::Agg) -> bool,
444    {
445        let split = Split::new(
446            &mut self.root,
447            SeekByRaccCond::<TreapSpec<M, L>, L, F>::new(f),
448            EqualSide::Left,
449        );
450        let node = split.left()?.rightmost();
451        self.node_id_manager.registered_node_id(node)
452    }
crates/competitive/src/data_structure/implicit_treap.rs (line 414)
405    pub fn insert(&mut self, index: usize, x: T::Key) {
406        assert!(index <= self.length);
407        let node = self.node(x);
408        if index == 0 {
409            self.root = ImplicitTreapSpec::<T>::merge(Some(node), self.root.take());
410        } else if index == self.length {
411            self.root = ImplicitTreapSpec::<T>::merge(self.root.take(), Some(node));
412        } else {
413            let mut node = Some(node);
414            let mut split = Split::new(&mut self.root, SeekBySize::new(index), EqualSide::Right);
415            split.manually_merge(|left, right| {
416                ImplicitTreapSpec::<T>::merge(
417                    ImplicitTreapSpec::<T>::merge(left, node.take()),
418                    right,
419                )
420            });
421        }
422        self.length += 1;
423    }
Source

pub fn left(&self) -> Option<BstImmutRef<'_, Spec>>

Examples found in repository?
crates/competitive/src/data_structure/treap.rs (line 450)
441    pub fn find_by_racc_cond<F>(&mut self, f: F) -> Option<BstNodeId<TreapSpec<M, L>>>
442    where
443        F: FnMut(&L::Agg) -> bool,
444    {
445        let split = Split::new(
446            &mut self.root,
447            SeekByRaccCond::<TreapSpec<M, L>, L, F>::new(f),
448            EqualSide::Left,
449        );
450        let node = split.left()?.rightmost();
451        self.node_id_manager.registered_node_id(node)
452    }
More examples
Hide additional examples
crates/competitive/src/data_structure/implicit_splay_tree.rs (line 371)
360    pub fn partition_point_acc<F>(&mut self, left: usize, mut pred: F) -> usize
361    where
362        F: FnMut(&T::Agg) -> bool,
363    {
364        let mut split3 = Split3::seek_by_size(&mut self.root, left..);
365        let front_size = split3
366            .left()
367            .map(|node| node.into_data().size)
368            .unwrap_or_default();
369        let split = split3.split_mid(SeekByAccCond::new(|acc| !pred(acc)), EqualSide::Right);
370        let index = split
371            .left()
372            .map(|node| node.into_data().size)
373            .unwrap_or_default();
374        front_size + index
375    }
376
377    pub fn rpartition_point_acc<F>(&mut self, right: usize, mut pred: F) -> usize
378    where
379        F: FnMut(&T::Agg) -> bool,
380    {
381        let mut split3 = Split3::seek_by_size(&mut self.root, ..right);
382        let split = split3.split_mid(SeekByRaccCond::new(|acc| !pred(acc)), EqualSide::Left);
383        split
384            .left()
385            .map(|node| node.into_data().size)
386            .unwrap_or_default()
387    }
crates/competitive/src/data_structure/implicit_treap.rs (line 475)
464    pub fn partition_point_acc<F>(&mut self, left: usize, mut pred: F) -> usize
465    where
466        F: FnMut(&T::Agg) -> bool,
467    {
468        let mut split3 = Split3::seek_by_size(&mut self.root, left..);
469        let front_size = split3
470            .left()
471            .map(|node| node.into_data().size)
472            .unwrap_or_default();
473        let split = split3.split_mid(SeekByAccCond::new(|acc| !pred(acc)), EqualSide::Right);
474        let index = split
475            .left()
476            .map(|node| node.into_data().size)
477            .unwrap_or_default();
478        front_size + index
479    }
480
481    pub fn rpartition_point_acc<F>(&mut self, right: usize, mut pred: F) -> usize
482    where
483        F: FnMut(&T::Agg) -> bool,
484    {
485        let mut split3 = Split3::seek_by_size(&mut self.root, ..right);
486        let split = split3.split_mid(SeekByRaccCond::new(|acc| !pred(acc)), EqualSide::Left);
487        split
488            .left()
489            .map(|node| node.into_data().size)
490            .unwrap_or_default()
491    }
Source

pub fn right(&self) -> Option<BstImmutRef<'_, Spec>>

Examples found in repository?
crates/competitive/src/data_structure/treap.rs (line 422)
412    pub fn find_by_key<Q>(&mut self, key: &Q) -> Option<BstNodeId<TreapSpec<M, L>>>
413    where
414        M: MonoidAct<Key: Borrow<Q>>,
415        Q: Ord + ?Sized,
416    {
417        let split = Split::new(
418            &mut self.root,
419            SeekByKey::<TreapSpec<M, L>, M::Key, Q>::new(key),
420            EqualSide::Right,
421        );
422        let node = split.right()?.leftmost();
423        matches!(node.into_data().key.key.borrow().cmp(key), Ordering::Equal)
424            .then(|| self.node_id_manager.registered_node_id(node))
425            .flatten()
426    }
427
428    pub fn find_by_acc_cond<F>(&mut self, f: F) -> Option<BstNodeId<TreapSpec<M, L>>>
429    where
430        F: FnMut(&L::Agg) -> bool,
431    {
432        let split = Split::new(
433            &mut self.root,
434            SeekByAccCond::<TreapSpec<M, L>, L, F>::new(f),
435            EqualSide::Right,
436        );
437        let node = split.right()?.leftmost();
438        self.node_id_manager.registered_node_id(node)
439    }
Source

pub fn left_datamut(&mut self) -> Option<BstDataMutRef<'_, Spec>>

Source

pub fn right_datamut(&mut self) -> Option<BstDataMutRef<'_, Spec>>

Source

pub fn manually_merge<F>(&mut self, f: F)
where F: FnMut(Option<BstRoot<Spec>>, Option<BstRoot<Spec>>) -> Option<BstRoot<Spec>>,

Examples found in repository?
crates/competitive/src/data_structure/implicit_treap.rs (lines 415-420)
405    pub fn insert(&mut self, index: usize, x: T::Key) {
406        assert!(index <= self.length);
407        let node = self.node(x);
408        if index == 0 {
409            self.root = ImplicitTreapSpec::<T>::merge(Some(node), self.root.take());
410        } else if index == self.length {
411            self.root = ImplicitTreapSpec::<T>::merge(self.root.take(), Some(node));
412        } else {
413            let mut node = Some(node);
414            let mut split = Split::new(&mut self.root, SeekBySize::new(index), EqualSide::Right);
415            split.manually_merge(|left, right| {
416                ImplicitTreapSpec::<T>::merge(
417                    ImplicitTreapSpec::<T>::merge(left, node.take()),
418                    right,
419                )
420            });
421        }
422        self.length += 1;
423    }

Trait Implementations§

Source§

impl<'a, Spec> Drop for Split<'a, Spec>
where Spec: BstSpec,

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl<'a, Spec> !Send for Split<'a, Spec>

§

impl<'a, Spec> !Sync for Split<'a, Spec>

§

impl<'a, Spec> !UnwindSafe for Split<'a, Spec>

§

impl<'a, Spec> Freeze for Split<'a, Spec>
where Option<BstNodeRef<Owned, Spec>>: Freeze, &'a mut Option<BstNodeRef<Owned, Spec>>: Freeze,

§

impl<'a, Spec> RefUnwindSafe for Split<'a, Spec>

§

impl<'a, Spec> Unpin for Split<'a, Spec>
where Option<BstNodeRef<Owned, Spec>>: Unpin, &'a mut Option<BstNodeRef<Owned, Spec>>: Unpin,

§

impl<'a, Spec> UnsafeUnpin for Split<'a, Spec>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToArrayVecScalar for T

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.