Struct skew_heap::SkewHeap [] [src]

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

A skew heap.

Methods

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

Returns an empty heap.

Returns true if the heap contains no items.

Returns the number of items in the heap.

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

Returns a reference to the heap's greatest item.

Returns None if the heap is empty.

Pushes the given item onto the heap.

Moves all items from the given heap into the heap.

Examples

use skew_heap::SkewHeap;

let mut h1 = SkewHeap::new();
h1.push(4);
h1.push(2);
h1.push(3);

let mut h2 = SkewHeap::new();
h2.push(1);
h2.push(8);

h1.append(&mut h2);

assert_eq!(h1.len(), 5);
assert_eq!(h1.peek(), Some(&8));

assert_eq!(h2.len(), 0);
assert_eq!(h2.peek(), None);

Removes all items from the heap.

Removes the heap's greatest item and returns it.

Returns None if the heap was empty.

Pushes the given item onto to the heap, then removes the heap's greatest item and returns it.

Examples

use skew_heap::SkewHeap;

let mut h = SkewHeap::new();

assert_eq!(h.push_pop(5), 5);
assert_eq!(h.len(), 0);
assert_eq!(h.peek(), None);

h.extend(&[4, 5]);
assert_eq!(h.len(), 2);
assert_eq!(h.peek(), Some(&5));

assert_eq!(h.push_pop(6), 6);
assert_eq!(h.len(), 2);
assert_eq!(h.peek(), Some(&5));

assert_eq!(h.push_pop(3), 5);
assert_eq!(h.len(), 2);
assert_eq!(h.peek(), Some(&4));

assert_eq!(h.pop(), Some(4));
assert_eq!(h.pop(), Some(3));
assert_eq!(h.pop(), None);

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

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

Examples

use skew_heap::SkewHeap;

let mut h = SkewHeap::new();

assert_eq!(h.replace(5), None);
assert_eq!(h.len(), 1);
assert_eq!(h.peek(), Some(&5));

assert_eq!(h.replace(4), Some(5));
assert_eq!(h.len(), 1);
assert_eq!(h.peek(), Some(&4));

assert_eq!(h.replace(6), Some(4));
assert_eq!(h.len(), 1);
assert_eq!(h.peek(), Some(&6));

assert_eq!(h.pop(), Some(6));
assert_eq!(h.pop(), None);

Trait Implementations

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

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

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

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

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

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

impl<'a, T: 'a + Ord + Copy> Extend<&'a T> for SkewHeap<T>
[src]

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

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

Creates a value from an iterator. Read more

impl<'a, T: 'a + Ord + Copy> FromIterator<&'a T> for SkewHeap<T>
[src]

Creates a value from an iterator. Read more

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

Formats the value using the given formatter.

impl<T: Ord> IntoIterator for SkewHeap<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 SkewHeap<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