Struct pairing_heap::PairingHeap [] [src]

pub struct PairingHeap<T: Ord> { /* fields omitted */ }

A priority queue based on a pairing heap.

Like BinaryHeap, PairingHeap is an implementation of a priority queue. Unlike BinaryHeap, PairingHeap provides an append method whose runtime is asymptotically optimal, at the cost of greater memory usage, slower iteration, and poor cache locality.

Time Complexity

Operation Time Complexity
append O(1)
peek O(1)
pop O(log n) (amortized)
push O(1)
push_pop O(log n) (amortized)
replace O(log n) (amortized)

Methods

impl<T: Ord> PairingHeap<T>
[src]

Returns a new heap.

Checks if the heap is empty.

Returns the number of items in the heap.

Returns an iterator that yields references to the items in the heap in arbitrary order.

Returns a reference to the greatest item in the heap.

Returns None if the heap is empty.

Pushes the given item onto the heap.

Moves the given heap's items into the heap, leaving the given heap empty.

This is equivalent to, but likely to be faster than, the following:

heap.extend(heap2.drain());

Pushes the given item onto the heap, then removes the greatest item in the heap and returns it.

This method is equivalent to, but likely faster than, the following:

heap.push(item);
let max = heap.pop().unwrap();

Removes the greatest item in the heap, then pushes the given item onto the heap.

Returns the item that was removed, or None if the heap was empty.

This method is equivalent to, but likely faster than, the following:

let max = heap.pop();
heap.push(item);

Removes the greatest item in the heap and returns it.

Returns None if the heap was empty.

If a call to this method is immediately preceded by a call to push, consider using push_pop instead. If a call to this method is immediately followed by a call to push, consider using replace instead.

Removes all items from the heap.

Removes all items from the heap and returns an iterator that yields them in arbitrary order.

All items are removed even if the iterator is not exhausted. However, the behavior of this method is unspecified if the iterator is leaked (e.g. via mem::forget).

Trait Implementations

impl<T: Clone + Ord> Clone for PairingHeap<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Ord + Debug> Debug for PairingHeap<T>
[src]

Formats the value using the given formatter.

impl<T: Ord> Default for PairingHeap<T>
[src]

Returns the "default value" for a type. Read more

impl<T: Ord> Extend<T> for PairingHeap<T>
[src]

Extends a collection with the contents of an iterator. Read more

impl<T: Ord> FromIterator<T> for PairingHeap<T>
[src]

Creates a value from an iterator. Read more

impl<T: Ord> IntoIterator for PairingHeap<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

impl<'a, T: Ord> IntoIterator for &'a PairingHeap<T>
[src]

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more