Skip to content

Commit 0e8b65e

Browse files
committed
okay
1 parent f26e530 commit 0e8b65e

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

src/sys/tree.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ impl<'treeseq> LLTree<'treeseq> {
6161
}
6262

6363
/// Return the virtual root of the tree.
64-
pub fn virtual_root(&self) -> tsk_id_t {
65-
self.as_ref().virtual_root
64+
pub fn virtual_root(&self) -> NodeId {
65+
self.as_ref().virtual_root.into()
6666
}
6767

6868
pub fn as_mut_ptr(&mut self) -> *mut tsk_tree_t {
@@ -79,7 +79,7 @@ impl<'treeseq> LLTree<'treeseq> {
7979

8080
pub fn left_sib(&self, u: NodeId) -> Option<NodeId> {
8181
super::tsk_column_access::<NodeId, _, _, _>(
82-
u.into(),
82+
u,
8383
self.as_ref().left_sib,
8484
unsafe {
8585
self.as_ref()
@@ -95,10 +95,9 @@ impl<'treeseq> LLTree<'treeseq> {
9595
)
9696
}
9797

98-
pub fn right_child<N: Into<tsk_id_t> + Copy>(&self, u: N) -> Option<tsk_id_t> {
99-
todo!("doc SAFETY");
100-
super::tsk_column_access::<tsk_id_t, _, _, _>(
101-
u.into(),
98+
pub fn right_child(&self, u: NodeId) -> Option<NodeId> {
99+
super::tsk_column_access::<NodeId, _, _, _>(
100+
u,
102101
self.as_ref().right_child,
103102
unsafe {
104103
self.as_ref()
@@ -118,7 +117,7 @@ impl<'treeseq> LLTree<'treeseq> {
118117
// Trait defining iteration over nodes.
119118
pub trait NodeIterator {
120119
fn next_node(&mut self);
121-
fn current_node(&mut self) -> Option<tsk_id_t>;
120+
fn current_node(&mut self) -> Option<NodeId>;
122121
}
123122

124123
struct NodeIteratorAdapter<T>
@@ -132,25 +131,27 @@ impl<T> Iterator for NodeIteratorAdapter<T>
132131
where
133132
T: NodeIterator,
134133
{
135-
type Item = tsk_id_t;
134+
type Item = NodeId;
136135
fn next(&mut self) -> Option<Self::Item> {
137136
self.ni.next_node();
138137
self.ni.current_node()
139138
}
140139
}
141140

142141
struct PreorderNodeIterator<'a> {
143-
current_root: tsk_id_t,
144-
node_stack: Vec<tsk_id_t>,
142+
current_root: NodeId,
143+
node_stack: Vec<NodeId>,
145144
tree: &'a LLTree<'a>,
146-
current_node_: Option<tsk_id_t>,
145+
current_node_: Option<NodeId>,
147146
}
148147

149148
impl<'a> PreorderNodeIterator<'a> {
150149
fn new(tree: &'a LLTree) -> Self {
151150
debug_assert!(tree.right_child(tree.virtual_root()).is_some());
152151
let mut rv = PreorderNodeIterator {
153-
current_root: tree.right_child(tree.virtual_root()).unwrap_or(-1),
152+
current_root: tree
153+
.right_child(tree.virtual_root())
154+
.unwrap_or(NodeId::NULL),
154155
node_stack: vec![],
155156
tree,
156157
current_node_: None,
@@ -159,7 +160,7 @@ impl<'a> PreorderNodeIterator<'a> {
159160
while c != -1 {
160161
rv.node_stack.push(c);
161162
debug_assert!(rv.tree.left_sib(c).is_some());
162-
c = rv.tree.left_sib(c).unwrap_or(-1);
163+
c = rv.tree.left_sib(c).unwrap_or(NodeId::NULL);
163164
}
164165
rv
165166
}
@@ -173,16 +174,16 @@ impl NodeIterator for PreorderNodeIterator<'_> {
173174
// because we later pop them from a steck
174175
// to generate the expected left-to-right ordering.
175176
debug_assert!(self.tree.right_child(u).is_some());
176-
let mut c = self.tree.right_child(u).unwrap_or(-1);
177+
let mut c = self.tree.right_child(u).unwrap_or(NodeId::NULL);
177178
while c != NodeId::NULL {
178179
self.node_stack.push(c);
179180
debug_assert!(self.tree.right_child(c).is_some());
180-
c = self.tree.left_sib(c).unwrap_or(-1);
181+
c = self.tree.left_sib(c).unwrap_or(NodeId::NULL);
181182
}
182183
};
183184
}
184185

185-
fn current_node(&mut self) -> Option<tsk_id_t> {
186+
fn current_node(&mut self) -> Option<NodeId> {
186187
self.current_node_
187188
}
188189
}

0 commit comments

Comments
 (0)