Interface MergeableHeap<T>
- Type Parameters:
T- The type of elements stored in the heap.
- All Known Implementing Classes:
AdjustableBinaryHeap,BinaryHeap
public interface MergeableHeap<T>
A mergeable heap data structure is a heap that allows for efficient merging of two heaps into a single heap. Elements stored in the heap must be comparable, and the provided comparator defines the ordering of the elements.
The merge operation combines both heaps into a new heap with all elements from
both heaps, maintaining the heap property defined by the comparator of the heap
invoking mergeWith(Heap).
- See Also:
-
Method Summary
-
Method Details
-
mergeWith
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);- Parameters:
other- heap- Returns:
thismerged with other- Throws:
ClassCastException- ifothernot the same instance asthis
-