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

    Modifier and Type
    Method
    Description
    mergeWith(Heap<T> other)
    Merges this heap with the other using this.Heap.comparator().
  • Method Details

    • mergeWith

      Heap<T> mergeWith(Heap<T> other)
      Merges this heap with the other using this.Heap.comparator(). The heaps will be merged regardless of other '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 with
           MergeableHeap<Heap<Integer>> b = new SomeMergeableHeapImpl(Comparator.reverseOrder(Integer::compare));
           // different implementations will have different time complexity
           a.mergeWith(b);
       
      Parameters:
      other - heap
      Returns:
      this merged with other
      Throws:
      ClassCastException - if other not the same instance as this