SHARE
TWEET

Untitled

a guest Aug 22nd, 2019 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fn traverse_tree(tree: &Tree, vec: BitVec) -> HashMap<u8, BitVec> {
  2.     match tree.data {
  3.         Some(byte) => {
  4.             let mut map = HashMap::with_capacity(1);
  5.             map.insert(byte, vec);
  6.             map
  7.         }
  8.         None => {
  9.             let mut left_vec = vec.clone();
  10.             left_vec.push(false);
  11.             let mut right_vec = vec.clone();
  12.             right_vec.push(true);
  13.             let left_map = traverse_tree(tree.left.unwrap().as_ref(), left_vec);
  14.             let right_map = traverse_tree(tree.right.unwrap().as_ref(), right_vec);
  15.             let mut map = HashMap::with_capacity(left_map.len() + right_map.len());
  16.             map.extend(left_map);
  17.             map.extend(right_map);
  18.             map
  19.         }
  20.     }
  21. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top