rbtree: debug impl
This commit is contained in:
parent
6645607c69
commit
07b90af46d
|
|
@ -1,3 +1,4 @@
|
|||
use core::fmt::Debug;
|
||||
use core::marker::PhantomData;
|
||||
use core::mem;
|
||||
use core::ops::Not;
|
||||
|
|
@ -657,6 +658,15 @@ pub struct RBTree<N: UnsafeNode> {
|
|||
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> {
|
||||
pub fn new() -> Self {
|
||||
Self { root: None }
|
||||
|
|
@ -1153,7 +1163,9 @@ impl<'a, N: UnsafeNode + 'a> Iterator for TreeIter<'a, N> {
|
|||
fn next(&mut self) -> Option<Self::Item> {
|
||||
self.range
|
||||
.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> {
|
||||
self.range
|
||||
.next_back()
|
||||
.map(|n| unsafe { n.node().unwrap().as_ref().key() })
|
||||
.as_ref()
|
||||
.and_then(Handle::node)
|
||||
.map(|n| unsafe { n.as_ref().key() })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue