org.supermind.crawl
Class HostQueuePriorityQueue

java.lang.Object
  extended by org.supermind.crawl.HostQueuePriorityQueue

public class HostQueuePriorityQueue
extends java.lang.Object

A HostQueuePriorityQueue maintains a partial ordering of its elements such that the least element can always be found in constant time. Put()'s and pop()'s require log(size) time.


Constructor Summary
HostQueuePriorityQueue(int maxSize)
           
 
Method Summary
 void adjustDown(HostQueue hq)
           
 void adjustTop()
          Should be called when the Object at top changes values.
 void adjustUp(HostQueue hq)
           
 void clear()
          Removes all entries from the HostQueuePriorityQueue.
protected  void downHeap(int i)
           
protected  void initialize(int maxSize)
          Subclass constructors must call this.
 void insert(HostQueue element)
          Adds element to the HostQueuePriorityQueue in log(size) time.
protected  boolean lessThan(HostQueue a, HostQueue b)
          Determines the ordering of objects in this priority queue.
 HostQueue pop()
          Removes and returns the least element of the HostQueuePriorityQueue in log(size) time.
 void put(HostQueue element)
          Adds an Object to a HostQueuePriorityQueue in log(size) time.
 int size()
          Returns the number of elements currently stored in the HostQueuePriorityQueue.
 HostQueue top()
          Returns the least element of the HostQueuePriorityQueue in constant time.
protected  void upHeap(int i)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HostQueuePriorityQueue

public HostQueuePriorityQueue(int maxSize)
Method Detail

adjustDown

public void adjustDown(HostQueue hq)

adjustTop

public final void adjustTop()
Should be called when the Object at top changes values. Still log(n) worst case, but it's at least twice as fast to
  { pq.top().change(); pq.adjustTop(); }
 
instead of
  { o = pq.pop(); o.change(); pq.push(o); }
 


adjustUp

public void adjustUp(HostQueue hq)

clear

public final void clear()
Removes all entries from the HostQueuePriorityQueue.


downHeap

protected final void downHeap(int i)

initialize

protected final void initialize(int maxSize)
Subclass constructors must call this.


insert

public void insert(HostQueue element)
Adds element to the HostQueuePriorityQueue in log(size) time.

Parameters:
element -

lessThan

protected boolean lessThan(HostQueue a,
                           HostQueue b)
Determines the ordering of objects in this priority queue. Subclasses must define this one method.


pop

public final HostQueue pop()
Removes and returns the least element of the HostQueuePriorityQueue in log(size) time.


put

public final void put(HostQueue element)
Adds an Object to a HostQueuePriorityQueue in log(size) time. If one tries to add more objects than maxSize from initialize a RuntimeException (ArrayIndexOutOfBound) is thrown.


size

public final int size()
Returns the number of elements currently stored in the HostQueuePriorityQueue.


top

public final HostQueue top()
Returns the least element of the HostQueuePriorityQueue in constant time.


upHeap

protected final void upHeap(int i)