Commit e68a0197 authored by SirBlueRabbit's avatar SirBlueRabbit
Browse files

rewrite is_zero_child to side

parent d4530758
......@@ -87,7 +87,7 @@ impl<V> Pool<Node<V>> {
self.cascade_flipped(v);
while let Some(p) = self[v].parent {
if self[p].parent.is_some() {
if self[p].flipped == (self.is_zero_child(v) == self.is_zero_child(p)) {
if self[p].flipped == (self.side(v) == self.side(p)) {
self.rotate(p);
self.rotate(v);
} else {
......@@ -120,14 +120,14 @@ impl<V> Pool<Node<V>> {
}
fn rotate(&mut self, v: Label<Node<V>>) {
let p_side = !self.is_zero_child(v);
let p_side = self.side(v);
let p = self[v].parent.unwrap();
let b_opt = self[v].children[usize::from(!p_side)];
let g_opt = self[p].parent;
self[v].parent = g_opt;
if let Some(g) = g_opt {
let g_side = !self.is_zero_child(p);
let g_side = self.side(p);
self[g].children[usize::from(g_side)] = Some(v);
} else {
self[v].path_parent = self[p].path_parent;
......@@ -142,10 +142,10 @@ impl<V> Pool<Node<V>> {
self[p].parent = Some(v);
}
fn is_zero_child(&self, v: Label<Node<V>>) -> bool {
fn side(&self, v: Label<Node<V>>) -> bool {
let p = self[v].parent.unwrap();
if let Some(z) = self[p].children[0] {
z == v
if let Some(o) = self[p].children[1] {
o == v
} else {
false
}
......
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