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,
impl<Data, Parent> BstNode<Data, Parent>where
Parent: Default,
Sourcepub fn new(data: Data) -> Self
pub fn new(data: Data) -> Self
Examples found in repository?
More examples
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>
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>
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> 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