Skip to content

Instantly share code, notes, and snippets.

View makoConstruct's full-sized avatar

mako yass makoConstruct

View GitHub Profile
fn rotate_right<A>(mut root: Nref<A>)-> Nref<A>{ //assumes root and leftofroot are some. I can't think of a way to take them as &ref Box<Node<A>> s, though, rightofleft might be None, and I need to be able to switch rightofleft with leftofroot.
let leftofroot = &mut root.unwrap().left;
let rightofleft = &mut root.unwrap().left.unwrap().right;
// transitions are as follows
// | root | leftofroot | rightofleft | -swap->
// | leftofroot | root | rightofleft | -swap->
// | leftofroot | rightofleft | root |
// left is now pointed by the previous owner of root[it is the new root of the tree cutting in question], left's right is now on the leftref of the old root, and the old root is the right child of the new root. That is the rotation we want.
swap(&mut root, leftofroot);
swap(leftofroot, rightofleft);

Keybase proof

I hereby claim:

  • I am makoConstruct on github.
  • I am makoconstruct (https://keybase.io/makoconstruct) on keybase.
  • I have a public key whose fingerprint is BBAE 04BD 3E96 4188 A47E 0C59 E892 D5FF 0077 2709

To claim this, I am signing this object: