SeekRight

Struct SeekRight 

Source
pub struct SeekRight<S> {
    _marker: PhantomData<fn() -> S>,
}

Fields§

§_marker: PhantomData<fn() -> S>

Implementations§

Source§

impl<S> SeekRight<S>

Source

pub fn new() -> Self

Examples found in repository?
crates/competitive/src/data_structure/splay_tree/node.rs (line 448)
441    pub fn merge(mut self, mut other: Self) -> Self {
442        if other.reborrow().left().is_none() {
443            S::top_down(other.borrow_datamut());
444            other.borrow_mut().set_left(Some(self));
445            S::bottom_up(other.borrow_datamut());
446            other
447        } else {
448            self = self.splay_by(SeekRight::new()).1;
449            self.borrow_mut().set_right(Some(other));
450            S::bottom_up(self.borrow_datamut());
451            self
452        }
453    }
454}
455
456impl<S> Root<S>
457where
458    S: SplaySpec,
459{
460    pub fn new(root: Option<NodeRef<marker::Owned, S>>) -> Self {
461        Self { root }
462    }
463    pub unsafe fn from_single_nodes(nodes: Vec<NodeRef<marker::Owned, S>>) -> Self {
464        unsafe { Self::from_single_nodes_inner(&nodes) }
465    }
466    unsafe fn from_single_nodes_inner(nodes: &[NodeRef<marker::Owned, S>]) -> Self {
467        if nodes.is_empty() {
468            Self::new(None)
469        } else {
470            let m = nodes.len() / 2;
471            let left = unsafe { Self::from_single_nodes_inner(&nodes[..m]) };
472            let right = unsafe { Self::from_single_nodes_inner(&nodes[m + 1..]) };
473            let mut node = NodeRef::new(nodes[m].node);
474            node.borrow_mut().set_left(left.root);
475            node.borrow_mut().set_right(right.root);
476            S::bottom_up(node.borrow_datamut());
477            Self::new(Some(node))
478        }
479    }
480    pub fn is_empty(&self) -> bool {
481        self.root.is_none()
482    }
483    pub fn root(&self) -> Option<NodeRef<marker::Immut<'_>, S>> {
484        Some(self.root.as_ref()?.reborrow())
485    }
486    pub fn root_data_mut(&mut self) -> Option<NodeRef<marker::DataMut<'_>, S>> {
487        Some(self.root.as_mut()?.borrow_datamut())
488    }
489    pub fn splay_by<Seeker>(&mut self, seeker: Seeker) -> Option<Ordering>
490    where
491        Seeker: SplaySeeker<S = S>,
492    {
493        let (ord, root) = self.root.take()?.splay_by(seeker);
494        self.root = Some(root);
495        Some(ord)
496    }
497    pub fn insert_left(&mut self, mut node: NodeRef<marker::Owned, S>) {
498        self.root = Some(match self.root.take() {
499            Some(root) => root.insert_left(node),
500            None => {
501                S::bottom_up(node.borrow_datamut());
502                node
503            }
504        });
505    }
506    pub fn insert_right(&mut self, mut node: NodeRef<marker::Owned, S>) {
507        self.root = Some(match self.root.take() {
508            Some(root) => root.insert_right(node),
509            None => {
510                S::bottom_up(node.borrow_datamut());
511                node
512            }
513        });
514    }
515    pub fn insert_first(&mut self, mut node: NodeRef<marker::Owned, S>) {
516        self.root = Some(match self.root.take() {
517            Some(root) => root.insert_first(node),
518            None => {
519                S::bottom_up(node.borrow_datamut());
520                node
521            }
522        });
523    }
524    pub fn insert_last(&mut self, mut node: NodeRef<marker::Owned, S>) {
525        self.root = Some(match self.root.take() {
526            Some(root) => root.insert_last(node),
527            None => {
528                S::bottom_up(node.borrow_datamut());
529                node
530            }
531        });
532    }
533    pub fn take_root(&mut self) -> Option<NodeRef<marker::Owned, S>> {
534        let mut root = self.root.take()?;
535        let right = root.borrow_mut().take_right();
536        self.root = root.borrow_mut().take_left();
537        self.append(&mut Self::new(right));
538        Some(root)
539    }
540    pub fn take_first(&mut self) -> Option<NodeRef<marker::Owned, S>> {
541        let mut root = self.root.take()?.splay_by(SeekLeft::new()).1;
542        let right = root.borrow_mut().take_right();
543        self.root = right;
544        Some(root)
545    }
546    pub fn take_last(&mut self) -> Option<NodeRef<marker::Owned, S>> {
547        let mut root = self.root.take()?.splay_by(SeekRight::new()).1;
548        let left = root.borrow_mut().take_left();
549        self.root = left;
550        Some(root)
551    }

Trait Implementations§

Source§

impl<S> Default for SeekRight<S>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<S> SplaySeeker for SeekRight<S>
where S: SplaySpec,

Source§

type S = S

Source§

fn splay_seek(&mut self, _node: NodeRef<Immut<'_>, Self::S>) -> Ordering

Auto Trait Implementations§

§

impl<S> Freeze for SeekRight<S>

§

impl<S> RefUnwindSafe for SeekRight<S>

§

impl<S> Send for SeekRight<S>

§

impl<S> Sync for SeekRight<S>

§

impl<S> Unpin for SeekRight<S>

§

impl<S> UnwindSafe for SeekRight<S>

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.