|
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()
|
Iterator<E> |
iterator()
|
Iterator<E> |
iterator(int startPriority,
int n)
|
boolean |
removeAll(Object o)
|
int |
size()
|
int |
size(int priority)
|
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 IllegalArgumentException
IllegalArgumentException - priorities or capacityPerPriority
is non-positive.
public BucketQueue(int[] capacities)
throws IllegalArgumentException
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)
IllegalArgumentException - priority is not a legal priority,
as determined by this' constructorpublic boolean removeAll(Object o)
public E extractMax()
throws NoSuchElementException
NoSuchElementException
public E getMax()
throws NoSuchElementException
NoSuchElementExceptionpublic int size()
public int size(int priority)
throws IllegalArgumentException
IllegalArgumentException - priority is not a legal priority,
as determined by this' constructorpublic boolean isEmpty()
public Iterator<E> iterator()
iterator in interface Iterable<E>
public Iterator<E> iterator(int startPriority,
int n)
throws IllegalArgumentException
IllegalArgumentException - startPriority is not a legal priority
as determined by this' constructor
public BucketQueue<E> clone()
throws CloneNotSupportedException
clone in class ObjectCloneNotSupportedExceptionpublic String toString()
toString in class Object
|
LimeWire Collection Component API | |||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||