harpoon.Util
Class BinHeapPriorityQueue

java.lang.Object
  |
  +--java.util.AbstractCollection
        |
        +--harpoon.Util.BinHeapPriorityQueue
All Implemented Interfaces:
Collection, MaxPriorityQueue

public class BinHeapPriorityQueue
extends AbstractCollection
implements MaxPriorityQueue

BinHeapPriorityQueue is an implementation of the PriorityQueue interface. It supports O(1) time peekMax and O(lg n) time insert and removeMax operations, assuming that ArrayList is implemented in a reasonable manner. The remove operation is probably slow however. Look into implementing a FibinocciHeap-based representation if speed becomes an issue.

Version:
$Id: BinHeapPriorityQueue.java,v 1.3 2002/02/26 22:47:24 cananian Exp $
Author:
Felix S. Klock II <pnkfelix@mit.edu>

Constructor Summary
BinHeapPriorityQueue()
          Creates a BinHeapPriorityQueue.
 
Method Summary
 void clear()
           
 boolean contains(Object o)
          This is slow.
 Object deleteMax()
          Returns and removes the Object in this with the highest priority.
 boolean equals(Object o)
           
 int hashCode()
           
 void insert(Object item, int priority)
          Inserts item into this, assigning it priority priority.
 boolean isEmpty()
           
 Iterator iterator()
          Returns the elements of this in no specific order.
 Object peekMax()
          Returns the Object in this with the highest priority.
 boolean remove(Object o)
          This is slow.
 int size()
           
 
Methods inherited from class java.util.AbstractCollection
add, addAll, containsAll, removeAll, retainAll, toArray, toArray, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Collection
add, addAll, containsAll, removeAll, retainAll, toArray, toArray
 

Constructor Detail

BinHeapPriorityQueue

public BinHeapPriorityQueue()
Creates a BinHeapPriorityQueue.

Method Detail

insert

public void insert(Object item,
                   int priority)
Description copied from interface: MaxPriorityQueue
Inserts item into this, assigning it priority priority.

Specified by:
insert in interface MaxPriorityQueue
Parameters:
item - Object being inserted
priority - Priority of item

peekMax

public Object peekMax()
Description copied from interface: MaxPriorityQueue
Returns the Object in this with the highest priority.

Specified by:
peekMax in interface MaxPriorityQueue

deleteMax

public Object deleteMax()
Description copied from interface: MaxPriorityQueue
Returns and removes the Object in this with the highest priority.

Specified by:
deleteMax in interface MaxPriorityQueue

clear

public void clear()
Specified by:
clear in interface Collection
Overrides:
clear in class AbstractCollection

contains

public boolean contains(Object o)
This is slow.

Specified by:
contains in interface Collection
Overrides:
contains in class AbstractCollection

equals

public boolean equals(Object o)
Specified by:
equals in interface Collection
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface Collection
Overrides:
hashCode in class Object

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Collection
Overrides:
isEmpty in class AbstractCollection

iterator

public Iterator iterator()
Returns the elements of this in no specific order.
effects: Creates a new Iterator which returns the elements of this
requires: this is not modified while the returned Iterator is in use.

Specified by:
iterator in interface Collection
Specified by:
iterator in class AbstractCollection

remove

public boolean remove(Object o)
This is slow.

Specified by:
remove in interface Collection
Overrides:
remove in class AbstractCollection

size

public int size()
Specified by:
size in interface Collection
Specified by:
size in class AbstractCollection