net.groboclown.gui.tripleBuffer.v1.test
Class Heap
java.lang.Object
|
+--net.groboclown.gui.tripleBuffer.v1.test.Heap
- public class Heap
- extends Object
Used for storing drawing elements, such as polygons and bitmaps, and sorting them according to a key.
Need to make this efficient, especially for the polygons (the polygons will probably just store a Long
whose value is (y * MAP_Y) + x).
Fibonacci heap could be used to merge the two heaps together, but they are too complex and require too much
memory for our purposes. Since we only have two heaps, it would be trivial to do a "on-the-fly" merge.
Keys are doubles, values are Objects
Uses an Array to store the values for efficiency, though we simulate a Vector. We keep the array filled with
HeapElements; those past
Constructor Summary |
Heap()
|
Heap(int initSize)
|
Heap(int initSize,
int incrementSize)
|
Methods inherited from class java.lang.Object |
, clone, equals, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
DEFAULT_SIZE
public static final int DEFAULT_SIZE
DEFAULT_INCREMENT_SIZE
public static final int DEFAULT_INCREMENT_SIZE
heap
HeapElement[] heap
size
int size
incSize
int incSize
currentSize
int currentSize
notDoneHeapify
boolean notDoneHeapify
Heap
public Heap()
Heap
public Heap(int initSize)
Heap
public Heap(int initSize,
int incrementSize)
main
public static void main(String[] args)
clear
public void clear()
- Cleans out all heap[i].value to eliminate memory leaks,
then sets the currentSize to 0.
add
public void add(double key,
Object val)
addSet
public void addSet(double[] keys,
Object[] vals,
int num)
length
public int length()
getCapacity
public int getCapacity()
peekNextKey
public double peekNextKey()
peekNextValue
public Object peekNextValue()
getNext
public Object getNext()
sort
public void sort()
heapify
protected void heapify(int i)
increaseArray
protected void increaseArray()
finalize
protected void finalize()
- Overrides:
finalize
in class Object
Written under the LGPL