|
LimeWire collection component api | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectorg.limewire.collection.BucketQueue<E>
public class BucketQueue<E>
Provides a discrete-case priority queue. BucketQueue is designed
to be a replacement for a binary heap for the special case when there
are only a small number of positive priorities. (Priorities are zero based
and therefore, when priority is set to 3, the values are [0, 1, 2]. Also, larger
numbers are higher priority.)
You determine how many element cases per priority are allowed in the queue.
When the queue attempts to add an element more than the maximum capacity for
the priority, the first element is removed upon insert(Object, int).
This class is not thread-safe.
//priorities, capacity
BucketQueue<String> bq = new BucketQueue<String>(3,2);
bq.insert("Abby", 1);
bq.insert("Bob", 1);
System.out.println(bq);
String returnFromInsert ;
returnFromInsert = bq.insert("Chris", 1);
if(returnFromInsert != null)
System.out.println("Element " + returnFromInsert + " popped because there are already 2 elements of priority 1.");
System.out.println(bq);
bq.insert("Dan", 2);
bq.insert("Eric", 2);
bq.insert("Fred", 0);
System.out.println("Max: " + bq.getMax().toString() + " and bq is " + bq);
Output:
[[], [Bob, Abby], []]
Element Abby popped because there are already 2 elements of priority 1.
[[], [Chris, Bob], []]
Max: Eric and bq is [[Eric, Dan], [Chris, Bob], [Fred]]
| Constructor Summary | |
|---|---|
BucketQueue(BucketQueue<? extends E> 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. |
BucketQueue<E> |
clone()
Returns a shallow copy of this, of type BucketQueue. |
E |
extractMax()
|
E |
getMax()
|
E |
insert(E o,
int priority)
|
boolean |
isEmpty()
|
java.util.Iterator<E> |
iterator()
|
java.util.Iterator<E> |
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 |
|---|
public BucketQueue(int priorities,
int capacityPerPriority)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - priorities or capacityPerPriority
is non-positive.
public BucketQueue(int[] capacities)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - capacities.length<=0 or
capacities[i]<=0 for any ipublic BucketQueue(BucketQueue<? extends E> other)
| Method Detail |
|---|
public void clear()
public E insert(E o,
int priority)
java.lang.IllegalArgumentException - priority is not a legal priority,
as determined by this' constructorpublic boolean removeAll(java.lang.Object o)
public E extractMax()
throws java.util.NoSuchElementException
java.util.NoSuchElementException
public E getMax()
throws java.util.NoSuchElementException
java.util.NoSuchElementExceptionpublic int size()
public int size(int priority)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - priority is not a legal priority,
as determined by this' constructorpublic boolean isEmpty()
public java.util.Iterator<E> iterator()
iterator in interface java.lang.Iterable<E>
public java.util.Iterator<E> iterator(int startPriority,
int n)
throws java.lang.IllegalArgumentException
java.lang.IllegalArgumentException - startPriority is not a legal priority
as determined by this' constructor
public BucketQueue<E> clone()
throws java.lang.CloneNotSupportedException
clone in class java.lang.Objectjava.lang.CloneNotSupportedExceptionpublic java.lang.String toString()
toString in class java.lang.Object
|
LimeWire collection component api | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||