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
ConstructorsConstructorDescriptionAdjustableBinaryHeap(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.booleandecreaseKey(T item, T decreasedItem) Try to decreaseitemif it's present in this heap.booleanincreaseKey(T item, T increasedItem) Try to increaseitemif 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:AdjustableHeapTry to increaseitemif it's present in this heap.- Specified by:
increaseKeyin interfaceAdjustableHeap<T>- Parameters:
item- to be increasedincreasedItem- increasing item- Returns:
- true if item is present and successfully increased
-
decreaseKey
Description copied from interface:AdjustableHeapTry to decreaseitemif it's present in this heap.- Specified by:
decreaseKeyin interfaceAdjustableHeap<T>- Parameters:
item- to be decreaseddecreasedItem- decreasing item- Returns:
- true if item is present and successfully decreased
-
mergeWith
Description copied from interface:MergeableHeapMerges 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:
mergeWithin interfaceMergeableHeap<T>- Overrides:
mergeWithin classBinaryHeap<T>- Parameters:
other- heap- Returns:
thismerged with other
-