rbtree: fix imports/mustuse

This commit is contained in:
janis 2026-08-03 00:28:15 +02:00
parent c9481b05c3
commit 83fd782c46
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8
2 changed files with 20 additions and 12 deletions

View file

@ -6,4 +6,4 @@ mod raw_node;
extern crate alloc;
pub use raw_node::{RBTree, TreeIter, TreeNodeIter};
pub use raw_node::{Color, RBTree, Side, TreeIter, TreeNodeIter, UnsafeNode};

View file

@ -709,6 +709,7 @@ impl<N: UnsafeNode> RBTree<N> {
}
}
#[must_use]
pub fn insert_node(&mut self, new_node: NonNull<N>) -> Option<NonNull<N>> {
let node_ref = unsafe { new_node.as_ref() };
@ -824,6 +825,7 @@ impl<N: UnsafeNode> RBTree<N> {
None
}
#[must_use]
pub fn remove<Q>(&mut self, key: &Q) -> Option<NonNull<N>>
where
N::Key: core::borrow::Borrow<Q>,
@ -993,11 +995,17 @@ impl<N: UnsafeNode> RBTree<N> {
z.node()
}
pub fn iter(&self) -> TreeNodeIter<'_, N> {
pub fn iter_nodes(&self) -> TreeNodeIter<'_, N> {
TreeNodeIter {
range: TreeRange::full_range(self.root_handle()),
}
}
pub fn iter(&self) -> TreeIter<'_, N> {
TreeIter {
range: TreeRange::full_range(self.root_handle()),
}
}
}
impl<N: UnsafeNode> Default for RBTree<N> {
@ -1227,7 +1235,7 @@ mod tests {
#[test]
fn next_of() {
let mut tree = RBTree::<TestNode>::new();
tree.insert_node(Box::into_non_null(Box::new(TestNode::new(1))));
_ = tree.insert_node(Box::into_non_null(Box::new(TestNode::new(1))));
assert_eq!(tree.root_handle().next_of(), None);
assert_eq!(tree.root_handle().next_back_of(), None);
@ -1245,11 +1253,11 @@ mod tests {
impl DummyTree {
fn new() -> Self {
let mut a = Box::into_non_null(Box::new(TestNode::new(1)));
let mut x = Box::into_non_null(Box::new(TestNode::new(2)));
let mut b = Box::into_non_null(Box::new(TestNode::new(3)));
let mut y = Box::into_non_null(Box::new(TestNode::new(4)));
let mut c = Box::into_non_null(Box::new(TestNode::new(5)));
let a = Box::into_non_null(Box::new(TestNode::new(1)));
let x = Box::into_non_null(Box::new(TestNode::new(2)));
let b = Box::into_non_null(Box::new(TestNode::new(3)));
let y = Box::into_non_null(Box::new(TestNode::new(4)));
let c = Box::into_non_null(Box::new(TestNode::new(5)));
unsafe {
x.as_ref().set_left(Some(a));
@ -1345,10 +1353,10 @@ mod tests {
for &node in &nodes {
eprintln!("Inserting node with key: {}", unsafe { (*node).key });
tree.insert_node(unsafe { NonNull::new_unchecked(node) });
_ = tree.insert_node(unsafe { NonNull::new_unchecked(node) });
eprintln!("Tree after insertion:");
for n in tree.iter() {
for n in tree.iter_nodes() {
eprintln!(
"\tNode: {:?} => {:?}",
unsafe { n.node().map(|n| n.as_ref().key) },
@ -1373,7 +1381,7 @@ mod tests {
.collect();
for &node in &nodes {
tree.insert_node(unsafe { NonNull::new_unchecked(node) });
_ = tree.insert_node(unsafe { NonNull::new_unchecked(node) });
}
for i in 0..10 {
@ -1389,7 +1397,7 @@ mod tests {
));
eprintln!("Tree after removal:");
for n in tree.iter() {
for n in tree.iter_nodes() {
eprintln!(
"\tNode: {:?} => {:?}",
unsafe { n.node().map(|n| n.as_ref().key) },