From 41f8763f18f2a3b1f40b8a08b20dcb50e47cdadb Mon Sep 17 00:00:00 2001 From: Janis Date: Fri, 15 Aug 2025 23:46:43 +0200 Subject: [PATCH] refactor(tree): remove unused constants, debug prints, and imports - Removed unused constants and redundant imports. - Eliminated debug print statements from the `search` module. - Added `#[allow(dead_code)]` annotations to suppress warnings for unused functions. - Made `Tree` and `as_subtree_mut` public --- src/tree.rs | 30 ++++++++++++------------------ 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/tree.rs b/src/tree.rs index 4ab267c..771de03 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -18,13 +18,6 @@ use core::{marker::PhantomData, mem::MaybeUninit, ptr::NonNull}; mod marker { use core::marker::PhantomData; - #[derive(Debug)] - pub struct LeafOrInternal; - #[derive(Debug)] - pub struct Leaf; - #[derive(Debug)] - pub struct Internal; - #[derive(Debug)] pub struct Edge; #[derive(Debug)] @@ -58,8 +51,6 @@ mod marker { impl BorrowType for DormantMut {} } -const CAPACITY: usize = 16; - #[derive(Debug)] struct LeafNode { parent: Option>, @@ -163,6 +154,7 @@ impl NodeRef { /// /// `edge.descend().ascend().unwrap()` and `node.ascend().unwrap().descend()` should /// both, upon success, do nothing. + #[allow(dead_code)] pub(super) fn ascend(self) -> Result, marker::Edge>, Self> { const { assert!(BorrowType::TRAVERSAL_PERMIT); @@ -220,6 +212,7 @@ impl<'a, K, V, HandleType> Handle, K, V>, HandleType> { /// dangerous. /// /// For details, see `NodeRef::reborrow_mut`. + #[allow(dead_code)] pub(super) unsafe fn reborrow_mut( &mut self, ) -> Handle, K, V>, HandleType> { @@ -266,6 +259,7 @@ impl NodeRef { } /// Slightly mutably borrows the owned root node. + #[allow(dead_code)] pub(super) fn borrow_valmut(&mut self) -> NodeRef, K, V> { NodeRef { node: self.node, @@ -275,6 +269,7 @@ impl NodeRef { /// Irreversibly transitions to a reference that permits traversal and offers /// destructive methods and little else. + #[allow(dead_code)] pub(super) fn into_dying(self) -> NodeRef { NodeRef { node: self.node, @@ -471,6 +466,7 @@ impl NodeRef { this.node.as_ptr() } + #[allow(dead_code)] fn as_leaf(&self) -> &LeafNode { // SAFETY: the static node type is `Leaf`. unsafe { &*Self::as_leaf_ptr(self) } @@ -540,6 +536,7 @@ pub(super) enum ForceResult { Internal(Node), } +#[allow(dead_code)] impl Handle, HandleType> { fn force(self) -> ForceResult, HandleType>> { match self.node.force() { @@ -645,6 +642,7 @@ impl NodeRef { } } +#[allow(dead_code)] impl Handle, marker::Edge> { /// Converts this edge handle into a value handle. /// IMPORTANT: this handle points to the value of the node, not the edge. @@ -778,17 +776,14 @@ mod search { match key.cmp(k.borrow()) { Ordering::Greater => {} Ordering::Equal => { - std::eprintln!("found key at index {}", start_index + offset); return IndexResult::Edge(start_index + offset); } Ordering::Less => { - std::eprintln!("insert key at index {}", start_index + offset); return IndexResult::Insert(start_index + offset); } } } - std::eprintln!("push_back key at index {}", keys.len()); IndexResult::Insert(keys.len()) } } @@ -796,7 +791,6 @@ mod search { #[cfg(test)] mod tests { use super::super::Tree; - use super::*; fn insert_and_dbg<'a>( tree: &'a mut Tree, @@ -837,9 +831,7 @@ enum HandleOrTree<'a, BorrowType, K, V, HandleType> { mod entry { use core::marker::PhantomData; - use crate::tree::LeafNode; - - use super::{Handle, NodeRef, Tree, borrow::DormantMutRef, marker}; + use super::{Handle, NodeRef, marker}; pub enum Entry<'a, Q: 'a, K: 'a, V: 'a> where @@ -1067,6 +1059,8 @@ mod subtree { } mod borrow { + #![allow(dead_code)] + use core::{marker::PhantomData, ptr::NonNull}; /// Models a reborrow of some unique reference, when you know that the reborrow @@ -1142,7 +1136,7 @@ mod borrow { type Root = NodeRef; -struct Tree { +pub struct Tree { root: Option>, _marker: PhantomData>, } @@ -1263,7 +1257,7 @@ impl Tree where K: Ord, { - fn as_subtree_mut<'a>(&'a mut self) -> Option>> { + pub fn as_subtree_mut<'a>(&'a mut self) -> Option>> { let root = self.root.as_mut()?.borrow_mut().dormant(); Some(subtree::Subtree {