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>
impl<E: TreapEntry> NodeMut<'_, E>
Sourcepub fn value_mut(&mut self) -> &mut E::Value
pub fn value_mut(&mut self) -> &mut E::Value
Returns an exclusive reference to the value of this node.
Sourcepub fn remove_from_treap(&mut self) -> E
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>>§
Sourcepub fn neighbors<'treap>(
&'treap self,
filter: &'treap E::FilteringKey,
skip_right: bool,
) -> impl Iterator<Item = &'treap Self>
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]);