Class AdjustableBinaryHeap<T>
java.lang.Object
com.abstractkamen.datastructures.impl.heaps.BinaryHeap<T>
com.abstractkamen.datastructures.impl.heaps.AdjustableBinaryHeap<T>
- Type Parameters:
T
- The type of elements stored in the heap, must be comparable.
- All Implemented Interfaces:
AdjustableHeap<T>
,Heap<T>
,MergeableHeap<T>
public class AdjustableBinaryHeap<T>
extends BinaryHeap<T>
implements Heap<T>, MergeableHeap<T>, AdjustableHeap<T>
An implementation of an adjustable binary heap data structure.
- See Also:
-
Field Summary
Fields inherited from class com.abstractkamen.datastructures.impl.heaps.BinaryHeap
DEFAULT_CAPACITY
-
Constructor Summary
ConstructorDescriptionAdjustableBinaryHeap
(Comparator<T> comparator) Create anAdjustableBinaryHeap<T>
with a custom comparatorAdjustableBinaryHeap
(Comparator<T> comparator, int capacity) Create anAdjustableBinaryHeap<T>
with a custom comparator -
Method Summary
Modifier and TypeMethodDescriptionstatic <T extends Comparable<T>>
AdjustableBinaryHeap<T>Create anAdjustableBinaryHeap<T>
with natural order comparator in a type safe way.static <T extends Comparable<T>>
AdjustableBinaryHeap<T>createComparable
(int capacity) Create anAdjustableBinaryHeap<T>
with natural order comparator in a type safe way.boolean
decreaseKey
(T item, T decreasedItem) Try to decreaseitem
if it's present in this heap.boolean
increaseKey
(T item, T increasedItem) Try to increaseitem
if it's present in this heap.Merges this heap with the other usingthis.
Heap.comparator()
.Methods inherited from class com.abstractkamen.datastructures.impl.heaps.BinaryHeap
comparator, getItems, heapifyDown, heapifyUp, isEmpty, peek, pop, push, restoreHeapOrder, size, toString
-
Constructor Details
-
AdjustableBinaryHeap
Create anAdjustableBinaryHeap<T>
with a custom comparator- Parameters:
comparator
- custom comparator
-
AdjustableBinaryHeap
Create anAdjustableBinaryHeap<T>
with a custom comparator- Parameters:
capacity
- initial capacitycomparator
- custom comparator
-
-
Method Details
-
createComparable
Create anAdjustableBinaryHeap<T>
with natural order comparator in a type safe way.- Type Parameters:
T
- comparable type
-
createComparable
Create anAdjustableBinaryHeap<T>
with natural order comparator in a type safe way.- Type Parameters:
T
- comparable type- Parameters:
capacity
- initial capacity
-
increaseKey
Description copied from interface:AdjustableHeap
Try to increaseitem
if it's present in this heap.- Specified by:
increaseKey
in interfaceAdjustableHeap<T>
- Parameters:
item
- to be increasedincreasedItem
- increasing item- Returns:
- true if item is present and successfully increased
-
decreaseKey
Description copied from interface:AdjustableHeap
Try to decreaseitem
if it's present in this heap.- Specified by:
decreaseKey
in interfaceAdjustableHeap<T>
- Parameters:
item
- to be decreaseddecreasedItem
- decreasing item- Returns:
- true if item is present and successfully decreased
-
mergeWith
Description copied from interface:MergeableHeap
Merges this heap with the other usingthis.
Heap.comparator()
. The heaps will be merged regardless ofother
's order. Depending on the implementation this may have an impact on performance.Example:
MergeableHeap<Heap<Integer>> a = new SomeMergeableHeapImpl(Integer::compare);
// can be merged withMergeableHeap<Heap<Integer>> b = new SomeMergeableHeapImpl(Comparator.reverseOrder(Integer::compare));
// different implementations will have different time complexity a.mergeWith(b);- Specified by:
mergeWith
in interfaceMergeableHeap<T>
- Overrides:
mergeWith
in classBinaryHeap<T>
- Parameters:
other
- heap- Returns:
this
merged with other
-