Package org.jheaps.array
Class AbstractArrayHeap<K>
- java.lang.Object
-
- org.jheaps.array.AbstractArrayWeakHeap<K>
-
- org.jheaps.array.AbstractArrayHeap<K>
-
- Type Parameters:
K
- the type of keys maintained by this heap
- All Implemented Interfaces:
java.io.Serializable
,Heap<K>
- Direct Known Subclasses:
BinaryArrayHeap
,DaryArrayHeap
,MinMaxBinaryArrayDoubleEndedHeap
abstract class AbstractArrayHeap<K> extends AbstractArrayWeakHeap<K>
Abstract implementation of a heap using an array representation.
-
-
Field Summary
Fields Modifier and Type Field Description private static long
serialVersionUID
-
Fields inherited from class org.jheaps.array.AbstractArrayWeakHeap
array, comparator, DOWNSIZING_MIN_HEAP_CAPACITY, MAX_HEAP_CAPACITY, MIN_HEAP_CAPACITY, minCapacity, size
-
-
Constructor Summary
Constructors Constructor Description AbstractArrayHeap(java.util.Comparator<? super K> comparator, int capacity)
Construct a new heap
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description K
deleteMin()
Delete and return an element with the minimum key.K
findMin()
Find an element with the minimum key.protected void
initCapacity(int capacity)
Initialize the array representationvoid
insert(K key)
Insert a key into the heap.-
Methods inherited from class org.jheaps.array.AbstractArrayWeakHeap
checkCapacity, clear, comparator, ensureCapacity, fixdown, fixdownWithComparator, fixup, fixupWithComparator, isEmpty, size
-
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AbstractArrayHeap
public AbstractArrayHeap(java.util.Comparator<? super K> comparator, int capacity)
Construct a new heap- Parameters:
comparator
- the comparator to usecapacity
- the initial capacity
-
-
Method Detail
-
initCapacity
protected void initCapacity(int capacity)
Initialize the array representation- Specified by:
initCapacity
in classAbstractArrayWeakHeap<K>
- Parameters:
capacity
- the capacity
-
findMin
public K findMin()
Find an element with the minimum key.- Returns:
- an element with the minimum key
-
insert
public void insert(K key)
Insert a key into the heap.- Parameters:
key
- the key to insert
-
deleteMin
public K deleteMin()
Delete and return an element with the minimum key. If multiple such elements exists, only one of them will be deleted.- Returns:
- the deleted element with the minimum key
-
-