Rename BinaryBuffer to PriorityBuffer
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/collections/trunk@131498 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
61c237e311
commit
00f8c54647
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BinaryHeap.java,v 1.18 2004/01/02 01:36:51 psteitz Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/BinaryHeap.java,v 1.19 2004/01/02 02:14:28 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -68,7 +68,7 @@ import java.util.NoSuchElementException;
|
||||||
* The <code>PriorityQueue</code> interface has now been replaced for most uses
|
* The <code>PriorityQueue</code> interface has now been replaced for most uses
|
||||||
* by the <code>Buffer</code> interface. This class and the interface are
|
* by the <code>Buffer</code> interface. This class and the interface are
|
||||||
* retained for backwards compatability. The intended replacement is
|
* retained for backwards compatability. The intended replacement is
|
||||||
* {@link org.apache.commons.collections.buffer.BinaryBuffer BinaryBuffer}.
|
* {@link org.apache.commons.collections.buffer.PriorityBuffer PriorityBuffer}.
|
||||||
* <p>
|
* <p>
|
||||||
* The removal order of a binary heap is based on either the natural sort
|
* The removal order of a binary heap is based on either the natural sort
|
||||||
* order of its elements or a specified {@link Comparator}. The
|
* order of its elements or a specified {@link Comparator}. The
|
||||||
|
@ -92,7 +92,7 @@ import java.util.NoSuchElementException;
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @since Commons Collections 1.0
|
* @since Commons Collections 1.0
|
||||||
* @version $Revision: 1.18 $ $Date: 2004/01/02 01:36:51 $
|
* @version $Revision: 1.19 $ $Date: 2004/01/02 02:14:28 $
|
||||||
*
|
*
|
||||||
* @author Peter Donald
|
* @author Peter Donald
|
||||||
* @author Ram Chidambaram
|
* @author Ram Chidambaram
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/buffer/Attic/BinaryBuffer.java,v 1.3 2004/01/02 01:36:51 psteitz Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/java/org/apache/commons/collections/buffer/PriorityBuffer.java,v 1.1 2004/01/02 02:14:29 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -85,14 +85,14 @@ import org.apache.commons.collections.BufferUnderflowException;
|
||||||
* Note that this implementation is not synchronized. Use
|
* Note that this implementation is not synchronized. Use
|
||||||
* {@link org.apache.commons.collections.BufferUtils#synchronizedBuffer(Buffer)} or
|
* {@link org.apache.commons.collections.BufferUtils#synchronizedBuffer(Buffer)} or
|
||||||
* {@link org.apache.commons.collections.buffer.SynchronizedBuffer#decorate(Buffer)}
|
* {@link org.apache.commons.collections.buffer.SynchronizedBuffer#decorate(Buffer)}
|
||||||
* to provide synchronized access to a <code>BinaryBuffer</code>:
|
* to provide synchronized access to a <code>PriorityBuffer</code>:
|
||||||
*
|
*
|
||||||
* <pre>
|
* <pre>
|
||||||
* Buffer heap = SynchronizedBuffer.decorate(new BinaryBuffer());
|
* Buffer heap = SynchronizedBuffer.decorate(new PriorityBuffer());
|
||||||
* </pre>
|
* </pre>
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0 (previously BinaryHeap v1.0)
|
* @since Commons Collections 3.0 (previously BinaryHeap v1.0)
|
||||||
* @version $Revision: 1.3 $ $Date: 2004/01/02 01:36:51 $
|
* @version $Revision: 1.1 $ $Date: 2004/01/02 02:14:29 $
|
||||||
*
|
*
|
||||||
* @author Peter Donald
|
* @author Peter Donald
|
||||||
* @author Ram Chidambaram
|
* @author Ram Chidambaram
|
||||||
|
@ -100,19 +100,19 @@ import org.apache.commons.collections.BufferUnderflowException;
|
||||||
* @author Paul Jack
|
* @author Paul Jack
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
public class BinaryBuffer extends AbstractCollection implements Buffer {
|
public class PriorityBuffer extends AbstractCollection implements Buffer {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The default capacity for a binary heap.
|
* The default capacity for the buffer.
|
||||||
*/
|
*/
|
||||||
private static final int DEFAULT_CAPACITY = 13;
|
private static final int DEFAULT_CAPACITY = 13;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The elements in this heap.
|
* The elements in this buffer.
|
||||||
*/
|
*/
|
||||||
protected Object[] elements;
|
protected Object[] elements;
|
||||||
/**
|
/**
|
||||||
* The number of elements currently in this heap.
|
* The number of elements currently in this buffer.
|
||||||
*/
|
*/
|
||||||
protected int size;
|
protected int size;
|
||||||
/**
|
/**
|
||||||
|
@ -131,7 +131,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* Constructs a new empty buffer that sorts in ascending order by the
|
* Constructs a new empty buffer that sorts in ascending order by the
|
||||||
* natural order of the objects added.
|
* natural order of the objects added.
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer() {
|
public PriorityBuffer() {
|
||||||
this(DEFAULT_CAPACITY, true, null);
|
this(DEFAULT_CAPACITY, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +142,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* @param comparator the comparator used to order the elements,
|
* @param comparator the comparator used to order the elements,
|
||||||
* null means use natural order
|
* null means use natural order
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(Comparator comparator) {
|
public PriorityBuffer(Comparator comparator) {
|
||||||
this(DEFAULT_CAPACITY, true, comparator);
|
this(DEFAULT_CAPACITY, true, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -153,7 +153,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* @param ascendingOrder if <code>true</code> the heap is created as a
|
* @param ascendingOrder if <code>true</code> the heap is created as a
|
||||||
* minimum heap; otherwise, the heap is created as a maximum heap
|
* minimum heap; otherwise, the heap is created as a maximum heap
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(boolean ascendingOrder) {
|
public PriorityBuffer(boolean ascendingOrder) {
|
||||||
this(DEFAULT_CAPACITY, ascendingOrder, null);
|
this(DEFAULT_CAPACITY, ascendingOrder, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,7 +165,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* @param comparator the comparator used to order the elements,
|
* @param comparator the comparator used to order the elements,
|
||||||
* null means use natural order
|
* null means use natural order
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(boolean ascendingOrder, Comparator comparator) {
|
public PriorityBuffer(boolean ascendingOrder, Comparator comparator) {
|
||||||
this(DEFAULT_CAPACITY, ascendingOrder, comparator);
|
this(DEFAULT_CAPACITY, ascendingOrder, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* @param capacity the initial capacity for the buffer, greater than zero
|
* @param capacity the initial capacity for the buffer, greater than zero
|
||||||
* @throws IllegalArgumentException if <code>capacity</code> is <= <code>0</code>
|
* @throws IllegalArgumentException if <code>capacity</code> is <= <code>0</code>
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(int capacity) {
|
public PriorityBuffer(int capacity) {
|
||||||
this(capacity, true, null);
|
this(capacity, true, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* null means use natural order
|
* null means use natural order
|
||||||
* @throws IllegalArgumentException if <code>capacity</code> is <= <code>0</code>
|
* @throws IllegalArgumentException if <code>capacity</code> is <= <code>0</code>
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(int capacity, Comparator comparator) {
|
public PriorityBuffer(int capacity, Comparator comparator) {
|
||||||
this(capacity, true, comparator);
|
this(capacity, true, comparator);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -202,7 +202,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* minimum heap; otherwise, the heap is created as a maximum heap.
|
* minimum heap; otherwise, the heap is created as a maximum heap.
|
||||||
* @throws IllegalArgumentException if <code>capacity</code> is <code><= 0</code>
|
* @throws IllegalArgumentException if <code>capacity</code> is <code><= 0</code>
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(int capacity, boolean ascendingOrder) {
|
public PriorityBuffer(int capacity, boolean ascendingOrder) {
|
||||||
this(capacity, ascendingOrder, null);
|
this(capacity, ascendingOrder, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ public class BinaryBuffer extends AbstractCollection implements Buffer {
|
||||||
* null means use natural order
|
* null means use natural order
|
||||||
* @throws IllegalArgumentException if <code>capacity</code> is <code><= 0</code>
|
* @throws IllegalArgumentException if <code>capacity</code> is <code><= 0</code>
|
||||||
*/
|
*/
|
||||||
public BinaryBuffer(int capacity, boolean ascendingOrder, Comparator comparator) {
|
public PriorityBuffer(int capacity, boolean ascendingOrder, Comparator comparator) {
|
||||||
super();
|
super();
|
||||||
if (capacity <= 0) {
|
if (capacity <= 0) {
|
||||||
throw new IllegalArgumentException("invalid capacity");
|
throw new IllegalArgumentException("invalid capacity");
|
|
@ -5,7 +5,7 @@ This package contains implementations of the
|
||||||
<p>
|
<p>
|
||||||
The following implementations are provided in the package:
|
The following implementations are provided in the package:
|
||||||
<ul>
|
<ul>
|
||||||
<li>BinaryBuffer - provides for removal based on a comparator ordering (priority queue)
|
<li>PriorityBuffer - provides for removal based on a comparator ordering
|
||||||
<li>BoundedFifoBuffer - implements a buffer with a fixed size that throws exceptions when full
|
<li>BoundedFifoBuffer - implements a buffer with a fixed size that throws exceptions when full
|
||||||
<li>CircularFifoBuffer - implements a buffer with a fixed size that discards oldest when full
|
<li>CircularFifoBuffer - implements a buffer with a fixed size that discards oldest when full
|
||||||
<li>UnboundedFifoBuffer - implements a buffer that grows in size if necessary
|
<li>UnboundedFifoBuffer - implements a buffer that grows in size if necessary
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/buffer/TestAll.java,v 1.3 2004/01/01 19:01:34 scolebourne Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/buffer/TestAll.java,v 1.4 2004/01/02 02:14:28 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -65,7 +65,7 @@ import junit.framework.TestSuite;
|
||||||
* Entry point for tests.
|
* Entry point for tests.
|
||||||
*
|
*
|
||||||
* @since Commons Collections 3.0
|
* @since Commons Collections 3.0
|
||||||
* @version $Revision: 1.3 $ $Date: 2004/01/01 19:01:34 $
|
* @version $Revision: 1.4 $ $Date: 2004/01/02 02:14:28 $
|
||||||
*
|
*
|
||||||
* @author Stephen Colebourne
|
* @author Stephen Colebourne
|
||||||
*/
|
*/
|
||||||
|
@ -83,14 +83,15 @@ public class TestAll extends TestCase {
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite = new TestSuite();
|
TestSuite suite = new TestSuite();
|
||||||
|
|
||||||
suite.addTest(TestBinaryBuffer.suite());
|
|
||||||
suite.addTest(TestBlockingBuffer.suite());
|
|
||||||
suite.addTest(TestBoundedFifoBuffer.suite());
|
suite.addTest(TestBoundedFifoBuffer.suite());
|
||||||
suite.addTest(TestBoundedFifoBuffer2.suite());
|
suite.addTest(TestBoundedFifoBuffer2.suite());
|
||||||
suite.addTest(TestCircularFifoBuffer.suite());
|
suite.addTest(TestCircularFifoBuffer.suite());
|
||||||
|
suite.addTest(TestPriorityBuffer.suite());
|
||||||
|
suite.addTest(TestUnboundedFifoBuffer.suite());
|
||||||
|
|
||||||
|
suite.addTest(TestBlockingBuffer.suite());
|
||||||
suite.addTest(TestPredicatedBuffer.suite());
|
suite.addTest(TestPredicatedBuffer.suite());
|
||||||
suite.addTest(TestTransformedBuffer.suite());
|
suite.addTest(TestTransformedBuffer.suite());
|
||||||
suite.addTest(TestUnboundedFifoBuffer.suite());
|
|
||||||
|
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/buffer/Attic/TestBinaryBuffer.java,v 1.2 2004/01/01 23:56:51 psteitz Exp $
|
* $Header: /home/jerenkrantz/tmp/commons/commons-convert/cvs/home/cvs/jakarta-commons//collections/src/test/org/apache/commons/collections/buffer/TestPriorityBuffer.java,v 1.1 2004/01/02 02:14:28 scolebourne Exp $
|
||||||
* ====================================================================
|
* ====================================================================
|
||||||
*
|
*
|
||||||
* The Apache Software License, Version 1.1
|
* The Apache Software License, Version 1.1
|
||||||
|
@ -74,30 +74,30 @@ import org.apache.commons.collections.comparators.ComparableComparator;
|
||||||
import org.apache.commons.collections.comparators.ReverseComparator;
|
import org.apache.commons.collections.comparators.ReverseComparator;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests the BinaryHeap.
|
* Tests the PriorityBuffer.
|
||||||
*
|
*
|
||||||
* @version $Revision: 1.2 $ $Date: 2004/01/01 23:56:51 $
|
* @version $Revision: 1.1 $ $Date: 2004/01/02 02:14:28 $
|
||||||
*
|
*
|
||||||
* @author Michael A. Smith
|
* @author Michael A. Smith
|
||||||
*/
|
*/
|
||||||
public class TestBinaryBuffer extends AbstractTestCollection {
|
public class TestPriorityBuffer extends AbstractTestCollection {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
junit.textui.TestRunner.run(suite());
|
junit.textui.TestRunner.run(suite());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
return new TestSuite(TestBinaryBuffer.class);
|
return new TestSuite(TestPriorityBuffer.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestBinaryBuffer(String testName) {
|
public TestPriorityBuffer(String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
public void verify() {
|
public void verify() {
|
||||||
super.verify();
|
super.verify();
|
||||||
BinaryBuffer heap = (BinaryBuffer) collection;
|
PriorityBuffer heap = (PriorityBuffer) collection;
|
||||||
|
|
||||||
Comparator c = heap.comparator;
|
Comparator c = heap.comparator;
|
||||||
if (c == null) {
|
if (c == null) {
|
||||||
|
@ -143,7 +143,7 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
* Return a new, empty {@link Object} to used for testing.
|
* Return a new, empty {@link Object} to used for testing.
|
||||||
*/
|
*/
|
||||||
public Collection makeCollection() {
|
public Collection makeCollection() {
|
||||||
return new BinaryBuffer();
|
return new PriorityBuffer();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------
|
//-----------------------------------------------------------------------
|
||||||
|
@ -174,7 +174,7 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasicOps() {
|
public void testBasicOps() {
|
||||||
BinaryBuffer heap = new BinaryBuffer();
|
PriorityBuffer heap = new PriorityBuffer();
|
||||||
|
|
||||||
heap.add("a");
|
heap.add("a");
|
||||||
heap.add("c");
|
heap.add("c");
|
||||||
|
@ -223,7 +223,7 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testBasicComparatorOps() {
|
public void testBasicComparatorOps() {
|
||||||
BinaryBuffer heap = new BinaryBuffer(new ReverseComparator(new ComparableComparator()));
|
PriorityBuffer heap = new PriorityBuffer(new ReverseComparator(new ComparableComparator()));
|
||||||
|
|
||||||
assertTrue("heap should be empty after create", heap.isEmpty());
|
assertTrue("heap should be empty after create", heap.isEmpty());
|
||||||
|
|
||||||
|
@ -292,7 +292,7 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
*/
|
*/
|
||||||
public void testAddRemove() {
|
public void testAddRemove() {
|
||||||
resetEmpty();
|
resetEmpty();
|
||||||
BinaryBuffer heap = (BinaryBuffer) collection;
|
PriorityBuffer heap = (PriorityBuffer) collection;
|
||||||
heap.add(new Integer(0));
|
heap.add(new Integer(0));
|
||||||
heap.add(new Integer(2));
|
heap.add(new Integer(2));
|
||||||
heap.add(new Integer(4));
|
heap.add(new Integer(4));
|
||||||
|
@ -323,12 +323,12 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
int heapSize = 100;
|
int heapSize = 100;
|
||||||
int operations = 20;
|
int operations = 20;
|
||||||
Random randGenerator = new Random();
|
Random randGenerator = new Random();
|
||||||
BinaryBuffer h = null;
|
PriorityBuffer h = null;
|
||||||
for(int i=0; i < iterations; i++) {
|
for(int i=0; i < iterations; i++) {
|
||||||
if (i < iterations / 2) {
|
if (i < iterations / 2) {
|
||||||
h = new BinaryBuffer(true);
|
h = new PriorityBuffer(true);
|
||||||
} else {
|
} else {
|
||||||
h = new BinaryBuffer(false);
|
h = new PriorityBuffer(false);
|
||||||
}
|
}
|
||||||
for(int r = 0; r < heapSize; r++) {
|
for(int r = 0; r < heapSize; r++) {
|
||||||
h.add( new Integer( randGenerator.nextInt(heapSize)) );
|
h.add( new Integer( randGenerator.nextInt(heapSize)) );
|
||||||
|
@ -345,7 +345,7 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
* Pops all elements from the heap and verifies that the elements come off
|
* Pops all elements from the heap and verifies that the elements come off
|
||||||
* in the correct order. NOTE: this method empties the heap.
|
* in the correct order. NOTE: this method empties the heap.
|
||||||
*/
|
*/
|
||||||
protected void checkOrder(BinaryBuffer h) {
|
protected void checkOrder(PriorityBuffer h) {
|
||||||
Integer lastNum = null;
|
Integer lastNum = null;
|
||||||
Integer num = null;
|
Integer num = null;
|
||||||
boolean fail = false;
|
boolean fail = false;
|
||||||
|
@ -365,7 +365,7 @@ public class TestBinaryBuffer extends AbstractTestCollection {
|
||||||
* Returns a string showing the contents of the heap formatted as a tree.
|
* Returns a string showing the contents of the heap formatted as a tree.
|
||||||
* Makes no attempt at padding levels or handling wrapping.
|
* Makes no attempt at padding levels or handling wrapping.
|
||||||
*/
|
*/
|
||||||
protected String showTree(BinaryBuffer h) {
|
protected String showTree(PriorityBuffer h) {
|
||||||
int count = 1;
|
int count = 1;
|
||||||
StringBuffer buffer = new StringBuffer();
|
StringBuffer buffer = new StringBuffer();
|
||||||
for (int offset = 1; count < h.size() + 1; offset *= 2) {
|
for (int offset = 1; count < h.size() + 1; offset *= 2) {
|
Loading…
Reference in New Issue