rbtree: debug impl

This commit is contained in:
janis 2026-08-04 00:27:10 +02:00
parent 6645607c69
commit 07b90af46d
Signed by: janis
SSH key fingerprint: SHA256:bB1qbbqmDXZNT0KKD5c2Dfjg53JGhj7B3CFcLIzSqq8

View file

@ -1,3 +1,4 @@
use core::fmt::Debug;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::mem; use core::mem;
use core::ops::Not; use core::ops::Not;
@ -657,6 +658,15 @@ pub struct RBTree<N: UnsafeNode> {
root: Option<NonNull<N>>, root: Option<NonNull<N>>,
} }
impl<N: UnsafeNode> Debug for RBTree<N>
where
N::Key: Debug,
{
fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
f.debug_set().entries(self.iter()).finish()
}
}
impl<N: UnsafeNode> RBTree<N> { impl<N: UnsafeNode> RBTree<N> {
pub fn new() -> Self { pub fn new() -> Self {
Self { root: None } Self { root: None }
@ -1153,7 +1163,9 @@ impl<'a, N: UnsafeNode + 'a> Iterator for TreeIter<'a, N> {
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
self.range self.range
.next() .next()
.map(|n| unsafe { n.node().unwrap().as_ref().key() }) .as_ref()
.and_then(Handle::node)
.map(|n| unsafe { n.as_ref().key() })
} }
} }
@ -1161,7 +1173,9 @@ impl<'a, N: UnsafeNode + 'a> DoubleEndedIterator for TreeIter<'a, N> {
fn next_back(&mut self) -> Option<Self::Item> { fn next_back(&mut self) -> Option<Self::Item> {
self.range self.range
.next_back() .next_back()
.map(|n| unsafe { n.node().unwrap().as_ref().key() }) .as_ref()
.and_then(Handle::node)
.map(|n| unsafe { n.as_ref().key() })
} }
} }