cl-structures: Tree cleanup

This commit is contained in:
John 2024-03-27 01:25:19 -05:00
parent 9f9a21b4c3
commit 66c29d601c
2 changed files with 4 additions and 1 deletions

View File

@ -158,6 +158,9 @@ impl<T> Node<T> {
std::mem::replace(&mut self.value, value) std::mem::replace(&mut self.value, value)
} }
pub fn parent(&self) -> Option<Ref<T>> {
self.parent
}
pub fn children(&self) -> &[Ref<T>] { pub fn children(&self) -> &[Ref<T>] {
&self.children &self.children
} }

View File

@ -10,7 +10,7 @@ use std::{marker::PhantomData, num::NonZeroUsize};
pub struct Ref<T: ?Sized>(NonZeroUsize, PhantomData<T>); pub struct Ref<T: ?Sized>(NonZeroUsize, PhantomData<T>);
impl<T: ?Sized> Ref<T> { impl<T: ?Sized> Ref<T> {
/// Constructs a new [TreeRef] with the given index /// Constructs a new [Ref] with the given index
pub fn new_unchecked(index: usize) -> Self { pub fn new_unchecked(index: usize) -> Self {
// Safety: index cannot be zero because we use saturating addition on unsigned type. // Safety: index cannot be zero because we use saturating addition on unsigned type.
Self( Self(