com.limegroup.gnutella.util
Class BucketQueue

java.lang.Object
  extended bycom.limegroup.gnutella.util.BucketQueue
All Implemented Interfaces:
java.lang.Cloneable

public class BucketQueue
extends java.lang.Object
implements java.lang.Cloneable

A discrete-case priority queue. Designed to be a replacement for BinaryHeap for the special case when there are only a small number of positive priorities, where larger numbers are higher priority. Unless otherwise noted, all methods have the same specifications as BinaryHeap. This also has a few additional methods not found in BinaryHeap. This class is not synchronized.


Constructor Summary
BucketQueue(BucketQueue other)
          "Copy constructor": constructs a a new shallow copy of other.
BucketQueue(int[] capacities)
           
BucketQueue(int priorities, int capacityPerPriority)
           
 
Method Summary
 void clear()
          Removes all elements from the queue.
 java.lang.Object clone()
          Returns a shallow copy of this, of type BucketQueue
 java.lang.Object extractMax()
           
 java.lang.Object getMax()
           
 java.lang.Object insert(java.lang.Object o, int priority)
           
 boolean isEmpty()
           
 java.util.Iterator iterator()
           
 java.util.Iterator iterator(int startPriority, int n)
           
 boolean removeAll(java.lang.Object o)
           
 int size()
           
 int size(int priority)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

BucketQueue

public BucketQueue(int priorities,
                   int capacityPerPriority)
            throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException - priorities or capacityPerPriority is non-positive.

BucketQueue

public BucketQueue(int[] capacities)
            throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException - capacities.length<=0 or capacities[i]<=0 for any i

BucketQueue

public BucketQueue(BucketQueue other)
"Copy constructor": constructs a a new shallow copy of other.

Method Detail

clear

public void clear()
Removes all elements from the queue.


insert

public java.lang.Object insert(java.lang.Object o,
                               int priority)
Throws:
java.lang.IllegalArgumentException - priority is not a legal priority, as determined by this' constructor

removeAll

public boolean removeAll(java.lang.Object o)

extractMax

public java.lang.Object extractMax()
                            throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

getMax

public java.lang.Object getMax()
                        throws java.util.NoSuchElementException
Throws:
java.util.NoSuchElementException

size

public int size()

size

public int size(int priority)
         throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException - priority is not a legal priority, as determined by this' constructor

isEmpty

public boolean isEmpty()

iterator

public java.util.Iterator iterator()

iterator

public java.util.Iterator iterator(int startPriority,
                                   int n)
                            throws java.lang.IllegalArgumentException
Throws:
java.lang.IllegalArgumentException - startPriority is not a legal priority as determined by this' constructor

clone

public java.lang.Object clone()
Returns a shallow copy of this, of type BucketQueue


toString

public java.lang.String toString()