Created
July 9, 2014 15:23
-
-
Save Gankra/aab30073fbaea499f72b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn splay (&mut self, node: &mut Node<T>) { | |
enum SplayType {NoSplay, Zig, ZigZig, ZigZag}; | |
loop { | |
let splayType = match node.get_parent() { | |
None => NoSplay, | |
Some(parent) => { | |
match parent.get_parent() { | |
None => Zig, | |
Some(_) => { | |
if parent.is_left() == node.is_left() { | |
ZigZig | |
} else { | |
ZigZag | |
} | |
} | |
} | |
} | |
}; | |
match splayType { | |
NoSplay => return, | |
Zig => self.rotate_up(node), | |
ZigZag => { | |
self.rotate_up(node); | |
self.rotate_up(node); | |
} | |
ZigZig => { | |
self.rotate_up(node.get_parent_mut().unwrap()); | |
self.rotate_up(node) | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment