pub fn push_heap_with<T>(slice: &mut [T], pred: fn(&T, &T) -> Option<Ordering>)
Expand description
Pushes an element into a heap, with a given predicate.
Given a slice where slice[0..len-1]
is a heap, then the element at
slice[len-1]
is pushed into the heap by bubbling it up to its correct
position.
ยงExamples
use heapify::*;
let mut vec = vec![5, 7, 9];
make_heap_with(&mut vec, |lhs, rhs| rhs.partial_cmp(lhs));
assert_eq!(peek_heap(&mut vec), Some(&5));
vec.push(8);
push_heap_with(&mut vec, |lhs, rhs| rhs.partial_cmp(lhs));
assert_eq!(peek_heap(&mut vec), Some(&5));
vec.push(3);
push_heap_with(&mut vec, |lhs, rhs| rhs.partial_cmp(lhs));
assert_eq!(peek_heap(&mut vec), Some(&3));