Skip to main content

NodeMut

Struct NodeMut 

Source
pub struct NodeMut<'handle, E: TreapEntry> { /* private fields */ }
Expand description

Node in the Treap.

It can be dereferenced into a shared reference to the TreapEntry, and it provides a mutable reference to the underlying value by NodeMut::value_mut.

You can also use Node::neighbors to get an iterator over the neighbors of this node.

And it can be used to remove the node from the treap by NodeMut::remove_from_treap.

Implementations§

Source§

impl<E: TreapEntry> NodeMut<'_, E>

Source

pub fn value_mut(&mut self) -> &mut E::Value

Returns an exclusive reference to the value of this node.

Source

pub fn remove_from_treap(&mut self) -> E

Removes this node from the associated Treap.

§Example
use orengine_utils::treap::{BaseTreapEntry, Treap};

let mut treap = Treap::<BaseTreapEntry<u32, u32, ()>>::new();

unsafe { treap.add(BaseTreapEntry::new(1, 1, ())) };

let mut node = treap.peek_max_with_filter_mut(&1).unwrap();
if node.sorting_key > 0 { // Remove on condition, you can use the node not to use search it again
    let entry = node.remove_from_treap();

    assert_eq!(entry.sorting_key, 1);
    assert!(treap.is_empty());
}

Methods from Deref<Target = Node<E>>§

Source

pub fn neighbors<'treap>( &'treap self, filter: &'treap E::FilteringKey, skip_right: bool, ) -> impl Iterator<Item = &'treap Self>

Returns an iterator over nodes reachable from self whose filtering_key() >= filter.

Traversal visits both subtree descendants and ancestors, pruning branches where the subtree’s max_filter < filter.

skip_right skips the right subtree on the first step, useful when the caller has already consumed the greatest node (e.g., after Treap::peek_max_with_filter).

§Example
use orengine_utils::treap::{BaseTreapEntry, Treap};

let mut treap = Treap::<BaseTreapEntry<usize, usize, ()>>::new();

for i in 1..=5 {
    treap.set(BaseTreapEntry::new(i, i, ()));
}

let node = treap.peek_max_with_filter(&3).unwrap();

let keys: Vec<_> = node.neighbors(&3, true) // `true` because we already know the greatest entry with `FilteringKey` >= 3
    .map(|n| n.sorting_key)
    .collect();

assert_eq!(keys, vec![5, 4, 3]);

Trait Implementations§

Source§

impl<E: TreapEntry> Deref for NodeMut<'_, E>

Source§

type Target = Node<E>

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.

Auto Trait Implementations§

§

impl<'handle, E> !Send for NodeMut<'handle, E>

§

impl<'handle, E> !Sync for NodeMut<'handle, E>

§

impl<'handle, E> !UnwindSafe for NodeMut<'handle, E>

§

impl<'handle, E> Freeze for NodeMut<'handle, E>

§

impl<'handle, E> RefUnwindSafe for NodeMut<'handle, E>

§

impl<'handle, E> Unpin for NodeMut<'handle, E>

§

impl<'handle, E> UnsafeUnpin for NodeMut<'handle, E>

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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
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.