pub fn insert_rec(&mut self, payload :u32, depth :u8) -> bool {
		//print!("INSERT payload {:?} depth {:?} ", payload, depth);
		if self.payload.is_some() {
			//println!(" => OCCUPIED AS LEAF");
			return false;
		}
		if depth == 0 {
			if !(self.l.is_none() && self.r.is_none()) {
				//println!(" => INNER NODE");
				return false;
			}
			self.payload = Some(payload);
			//println!(" => ADDED");
			return true;
		}
		if self.even_childs {
			//println!(" => HAS EVEN CHILDS");
			match &mut self.l {
				&mut Some(_) => return false,
				&mut None => {
					let mut new_node = HuffTree { even_childs :true, payload :None, l :None, r :None };
					new_node.insert_rec(payload, depth - 1);
					self.l = Some(Box::new(new_node));
					self.even_childs = false;
					return true;
				}
			}
		} else {
			//println!(" => HAS NOT EVEN CHILDS");
			// First try left branch
			let left = self.l.as_mut().unwrap();
			if !left.even_childs {
				if left.insert_rec(payload, depth - 1) {
					self.even_childs = left.even_childs &&
						if let &mut Some(ref mut right) = &mut self.r.as_mut() { right.even_childs } else { false };
					return true;
				}
			}
			// Left sub tree was either full or leaf
			// Therefore, put it in the right branch now
			// As left has even_childs == true, right causes
			// us to have even_childs == false.
			return match self.r {
				Some(ref mut right) => {
					let success = right.insert_rec(payload, depth - 1);
					self.even_childs = left.even_childs && right.even_childs;
					success
				},
				None => {
					let mut new_node = HuffTree { even_childs :true, payload :None, l :None, r :None };
					let success = new_node.insert_rec(payload, depth - 1);
					self.even_childs = left.even_childs && new_node.even_childs;
					self.r = Some(Box::new(new_node));
					success
				}
			};
		}
	}
/// Returns whether the addition was successful
Returns whether the addition was successful
Returns whether the addition was successful
pub fn insert_rec(&mut self, payload :u32, depth :u8) -> bool {
		//print!("INSERT payload {:?} depth {:?} ", payload, depth);
		if self.payload.is_some() {
			//println!(" => OCCUPIED AS LEAF");
			return false;
		}
		if depth == 0 {
			if !(self.l.is_none() && self.r.is_none()) {
				//println!(" => INNER NODE");
				return false;
			}
			self.payload = Some(payload);
			//println!(" => ADDED");
			return true;
		}
		if self.even_childs {
			//println!(" => HAS EVEN CHILDS");
			match &mut self.l {
				&mut Some(_) => return false,
				&mut None => {
					let mut new_node = HuffTree { even_childs :true, payload :None, l :None, r :None };
					new_node.insert_rec(payload, depth - 1);
					self.l = Some(Box::new(new_node));
					self.even_childs = false;
					return true;
				}
			}
		} else {
			//println!(" => HAS NOT EVEN CHILDS");
			// First try left branch
			let left = self.l.as_mut().unwrap();
			if !left.even_childs {
				if left.insert_rec(payload, depth - 1) {
					self.even_childs = left.even_childs &&
						if let &mut Some(ref mut right) = &mut self.r.as_mut() { right.even_childs } else { false };
					return true;
				}
			}
			// Left sub tree was either full or leaf
			// Therefore, put it in the right branch now
			// As left has even_childs == true, right causes
			// us to have even_childs == false.
			return match self.r {
				Some(ref mut right) => {
					let success = right.insert_rec(payload, depth - 1);
					self.even_childs = left.even_childs && right.even_childs;
					success
				},
				None => {
					let mut new_node = HuffTree { even_childs :true, payload :None, l :None, r :None };
					let success = new_node.insert_rec(payload, depth - 1);
					self.even_childs = left.even_childs && new_node.even_childs;
					self.r = Some(Box::new(new_node));
					success
				}
			};
		}
	}
pub fn insert_rec ( & mut self , payload : u32 , depth : u8 ) -> bool { //print!("INSERT payload {:?} depth {:?} ", payload, depth); if self . payload . is_some ( ) { //println!(" => OCCUPIED AS LEAF"); return false ; } if depth == 0 { if ! ( self . l . is_none ( ) && self . r . is_none ( ) ) { //println!(" => INNER NODE"); return false ; } self . payload = Some ( payload ) ; //println!(" => ADDED"); return true ; } if self . even_childs { //println!(" => HAS EVEN CHILDS"); match & mut self . l { & mut Some ( _ ) => return false , & mut None => { let mut new_node = HuffTree { even_childs : true , payload : None , l : None , r : None } ; new_node . insert_rec ( payload , depth - 1 ) ; self . l = Some ( Box :: new ( new_node ) ) ; self . even_childs = false ; return true ; } } } else { //println!(" => HAS NOT EVEN CHILDS"); // First try left branch let left = self . l . as_mut ( ) . unwrap ( ) ; if ! left . even_childs { if left . insert_rec ( payload , depth - 1 ) { self . even_childs = left . even_childs && if let & mut Some ( ref mut right ) = & mut self . r . as_mut ( ) { right . even_childs } else { false } ; return true ; } } // Left sub tree was either full or leaf // Therefore, put it in the right branch now // As left has even_childs == true, right causes // us to have even_childs == false. return match self . r { Some ( ref mut right ) => { let success = right . insert_rec ( payload , depth - 1 ) ; self . even_childs = left . even_childs && right . even_childs ; success } , None => { let mut new_node = HuffTree { even_childs : true , payload : None , l : None , r : None } ; let success = new_node . insert_rec ( payload , depth - 1 ) ; self . even_childs = left . even_childs && new_node . even_childs ; self . r = Some ( Box :: new ( new_node ) ) ; success } } ; } }
Returns whether the addition was successful
Returns whether the addition was successful
&mut self
payload
u32
depth
u8
&mut self
payload
u32
depth
u8