Open przygienda opened 7 years ago
fn pop(&mut self) -> Option<(Self::Handle, Cost)> { if self.binary_tree.is_empty() { return None; } if self.binary_tree.len() > 1 { let element = self.binary_tree.swap_remove(0); self.update_handle(0); self.heap_down(0); self.handle_to_index[element.handle as usize] = usize::max_value(); Some((element.handle, element.cost)) } else { let element = self.binary_tree[0]; self.binary_tree.clear(); self.handle_to_index[element.handle as usize] = usize::max_value(); Some((element.handle, element.cost)) } } #[test] fn in_heap() { let mut h: AddressableBinaryHeap<u64> = AddressableBinaryHeap::new(10); h.push(0,1); assert!(h.in_heap(0)); h.push(1,2); assert!(h.in_heap(1)); h.pop(); h.pop(); assert!(!h.in_heap(0)); assert!(!h.in_heap(1)); h.push(0,1); assert!(h.in_heap(0)); }
in fact checking on something like
const INVALID : usize = usize::max_value();
would be much cleaner ...