Skip to main content

BstNode

Struct BstNode 

Source
pub struct BstNode<Data, Parent = WithNoParent<Data>> {
    pub data: Data,
    pub parent: Parent,
    pub child: [Option<NonNull<BstNode<Data, Parent>>>; 2],
}

Fields§

§data: Data§parent: Parent§child: [Option<NonNull<BstNode<Data, Parent>>>; 2]

Implementations§

Source§

impl<Data, Parent> BstNode<Data, Parent>
where Parent: Default,

Source

pub fn new(data: Data) -> Self

Examples found in repository?
crates/competitive/src/data_structure/binary_search_tree/node.rs (line 344)
340    pub fn from_data<A>(data: Spec::Data, allocator: &mut A) -> Self
341    where
342        A: Allocator<BstNode<Spec::Data, Spec::Parent>>,
343    {
344        Self::new(allocator.allocate(BstNode::new(data)))
345    }
More examples
Hide additional examples
crates/competitive/src/tree/link_cut_tree.rs (lines 192-195)
190    pub fn add_node(&mut self, value: S::Value) -> usize {
191        let index = self.nodes.len();
192        let node = self.allocator.allocate(BstNode::new(LinkCutData {
193            inner: S::new(value),
194            index_and_reverse: index << 1,
195        }));
196        self.nodes.push(node);
197        index
198    }
crates/competitive/src/tree/top_tree.rs (lines 350-358)
347    pub fn add_node(&mut self, info: S::Info) -> usize {
348        let index = self.nodes.len();
349        let sum = S::vertex(&info);
350        let node = self.node_allocator.allocate(BstNode::new(TopTreeData {
351            info,
352            sum,
353            light: None,
354            belong: None,
355            heavy_action: <A::ActionMonoid as Unital>::unit(),
356            light_action: <A::ActionMonoid as Unital>::unit(),
357            index_and_reverse: index << 1,
358        }));
359        self.nodes.push(node);
360        index
361    }
362
363    fn node(&self, index: usize) -> TopPtr<S, A> {
364        self.nodes[index]
365    }
366
367    #[inline]
368    unsafe fn pull_top(node: TopPtr<S, A>) {
369        unsafe { TopBstSpec::<S, A>::bottom_up(BstDataMutRef::new_unchecked(node)) };
370    }
371
372    #[inline]
373    unsafe fn pull_rake(node: RakePtr<S, A>) {
374        unsafe { RakeBstSpec::<S, A>::bottom_up(BstDataMutRef::new_unchecked(node)) };
375    }
376
377    #[inline]
378    unsafe fn splay_top(node: TopPtr<S, A>) {
379        let root = if A::ROOT_TO_NODE_TOP_DOWN {
380            unsafe {
381                splay_operations::with_parent::splay::<TopBstSpec<S, A>, TopTreeData<S, A>>(node)
382            }
383        } else {
384            unsafe {
385                splay_operations::with_parent::splay_with_local_top_down::<
386                    TopBstSpec<S, A>,
387                    TopTreeData<S, A>,
388                >(node)
389            }
390        };
391        if root != node {
392            unsafe {
393                (*node.as_ptr()).data.belong = (*root.as_ptr()).data.belong.take();
394            }
395        }
396    }
397
398    #[inline]
399    unsafe fn splay_rake(node: RakePtr<S, A>) {
400        unsafe {
401            splay_operations::with_parent::splay_with_local_top_down::<
402                RakeBstSpec<S, A>,
403                RakeData<S, A>,
404            >(node)
405        };
406    }
407
408    unsafe fn rake_rightmost(mut node: RakePtr<S, A>) -> RakePtr<S, A> {
409        loop {
410            unsafe { RakeBstSpec::<S, A>::top_down(BstDataMutRef::new_unchecked(node)) };
411            match unsafe { node.as_ref().child[1] } {
412                Some(right) => node = right,
413                None => return node,
414            }
415        }
416    }
417
418    unsafe fn rake_insert(
419        &mut self,
420        root: Option<RakePtr<S, A>>,
421        key: S::Point,
422    ) -> (RakePtr<S, A>, RakePtr<S, A>) {
423        let mut node = self.rake_allocator.allocate(BstNode::new(RakeData {
424            sum: key.clone(),
425            key,
426            action: <A::ActionMonoid as Unital>::unit(),
427            buffer: <A::ActionMonoid as Unital>::unit(),
428        }));
429        if let Some(mut root) = root {
430            unsafe {
431                node.as_mut().child[0] = Some(root);
432                root.as_mut().parent.parent = Some(node);
433                Self::pull_rake(node);
434            }
435        }
436        (node, node)
437    }

Auto Trait Implementations§

§

impl<Data, Parent = WithNoParent<Data>> !Send for BstNode<Data, Parent>

§

impl<Data, Parent = WithNoParent<Data>> !Sync for BstNode<Data, Parent>

§

impl<Data, Parent> Freeze for BstNode<Data, Parent>
where Data: Freeze, Parent: Freeze, [Option<NonNull<BstNode<Data, Parent>>>; 2]: Freeze,

§

impl<Data, Parent> RefUnwindSafe for BstNode<Data, Parent>
where Data: RefUnwindSafe, Parent: RefUnwindSafe, [Option<NonNull<BstNode<Data, Parent>>>; 2]: RefUnwindSafe,

§

impl<Data, Parent> Unpin for BstNode<Data, Parent>
where Data: Unpin, Parent: Unpin, [Option<NonNull<BstNode<Data, Parent>>>; 2]: Unpin,

§

impl<Data, Parent> UnsafeUnpin for BstNode<Data, Parent>
where Data: UnsafeUnpin, Parent: UnsafeUnpin, [Option<NonNull<BstNode<Data, Parent>>>; 2]: UnsafeUnpin,

§

impl<Data, Parent> UnwindSafe for BstNode<Data, Parent>
where Data: UnwindSafe, Parent: UnwindSafe, [Option<NonNull<BstNode<Data, Parent>>>; 2]: UnwindSafe,

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.