Commit 88f9e132 authored by SirBlueRabbit's avatar SirBlueRabbit
Browse files

cleanup lct

parent 37fce0ea
......@@ -172,28 +172,13 @@ impl<V> Pool<Node<V>> {
self[u].d_depth = 0;
}
/* pub fn first_ancestor(&mut self, u: Label<Node<V>>, v: Label<Node<V>>) -> Label<Node<V>> {
self.expose(u);
self.expose(v);
let mut x = u;
while let Parent::BinTree(y) = self[x].parent {
x = y;
}
match self[x].parent {
Parent::BinTree(_) => unreachable!(),
Parent::Path(y) => y,
Parent::Root => v,
}
} */
pub fn depth(&self, u: Label<Node<V>>) -> usize {
let mut label = u;
let mut depth: isize = 0;
loop {
let d_depth = self[label].d_depth as isize;
if self.parent(label).is_some() {
let d_depth = self[label].d_depth as isize;
let d_flip = self[self.parent(label).unwrap()].d_flip;
let child_type = self.child_type(label);
......@@ -209,7 +194,6 @@ impl<V> Pool<Node<V>> {
}
label = self.parent(label).unwrap();
} else {
let d_depth = self[label].d_depth as isize;
return (depth + d_depth).abs() as usize;
}
}
......@@ -414,7 +398,6 @@ mod tests {
// rotate
lct.rotate(o);
dbg!(&lct);
// check children
assert_eq!(lct[o].children, Children(None, Some(p)));
......@@ -716,49 +699,9 @@ mod tests {
lct.link(b, c);
lct.expose(b);
lct.expose(a);
//lct.expose(c);
lct.splay(c);
if let Some(child) = lct[c].children[ChildType::from(true)] {
lct[child].parent = Parent::Path(c);
lct[c].children[ChildType::from(true)] = None;
}
while let Parent::Path(p) = lct[c].parent {
lct.splay(p);
// check depths
println!("after splaying {p}:");
dbg!(&lct);
assert_eq!(lct.depth(a), 0);
assert_eq!(lct.depth(b), 1);
assert_eq!(lct.depth(c), 2);
if let Some(x) = lct[p].children[ChildType::from(true)] {
lct[x].parent = Parent::Path(p);
}
lct[p].children[ChildType::from(true)] = Some(c);
lct[c].parent = Parent::BinTree(p);
// check depths
println!("after reassigning children of {p}:");
dbg!(&lct);
assert_eq!(lct.depth(a), 0);
assert_eq!(lct.depth(b), 1);
assert_eq!(lct.depth(c), 2);
lct.rotate(c);
// check depths
println!("after rotating {c}:");
dbg!(&lct);
assert_eq!(lct.depth(a), 0);
assert_eq!(lct.depth(b), 1);
assert_eq!(lct.depth(c), 2);
}
lct.expose(c);
// check depths
dbg!(&lct);
assert_eq!(lct.depth(a), 0);
assert_eq!(lct.depth(b), 1);
assert_eq!(lct.depth(c), 2);
......@@ -808,15 +751,9 @@ mod tests {
let label1 = Label::from(fastrand::usize(0..size));
let label2 = Label::from(fastrand::usize(0..size));
if label1 != label2 {
// evert
dbg!(&label1);
// restructure tree
lct.evert(label1);
dbg!(&lct);
// expose
dbg!(&label2);
lct.expose(label2);
dbg!(&lct);
assert_depth(&lct, label2);
// find a node to cut
......@@ -824,7 +761,7 @@ mod tests {
let index = fastrand::usize(0..depth);
let cut = lct.index_depth(label2, index + 1);
// cut and link back
// cut and link back together
lct.cut(cut);
lct.evert(label2);
lct.link(label1, label2);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment