@Override
    @ConstantTime(amortized = true)
    public void meld(MergeableAddressableHeap<K, V> other) {
        CostlessMeldPairingHeap<K, V> h = (CostlessMeldPairingHeap<K, V>) other;

        // check same comparator
        if (comparator != null) {
            if (h.comparator == null || !h.comparator.equals(comparator)) {
                throw new IllegalArgumentException("Cannot meld heaps using different comparators!");
            }
        } else if (h.comparator != null) {
            throw new IllegalArgumentException("Cannot meld heaps using different comparators!");
        }

        if (h.other != h) {
            throw new IllegalStateException("A heap cannot be used after a meld.");
        }

        // meld
        if (size < h.size) {
            consolidate();

            if (comparator == null) {
                root = link(h.root, root);
            } else {
                root = linkWithComparator(h.root, root);
            }
            decreasePoolSize = h.decreasePoolSize;
            h.decreasePoolSize = 0;

            decreasePoolMinPos = h.decreasePoolMinPos;
            h.decreasePoolMinPos = 0;

            Node<K, V>[] tmp = decreasePool;
            decreasePool = h.decreasePool;
            h.decreasePool = tmp;
        } else {
            h.consolidate();

            if (comparator == null) {
                root = link(h.root, root);
            } else {
                root = linkWithComparator(h.root, root);
            }
        }

        size += h.size;
        h.root = null;
        h.size = 0;

        // take ownership
        h.other = this;
    }
@ Override @ ConstantTime ( amortized = true ) public void meld ( MergeableAddressableHeap < K , V > other ) { CostlessMeldPairingHeap < K , V > h = ( CostlessMeldPairingHeap < K , V > ) other ; if ( comparator != null ) { if ( h . comparator == null || ! h . comparator . equals ( comparator ) ) { throw new IllegalArgumentException ( "Cannot meld heaps using different comparators!" ) ; } } else if ( h . comparator != null ) { throw new IllegalArgumentException ( "Cannot meld heaps using different comparators!" ) ; } if ( h . other != h ) { throw new IllegalStateException ( "A heap cannot be used after a meld." ) ; } if ( size < h . size ) { consolidate ( ) ; if ( comparator == null ) { root = link ( h . root , root ) ; } else { root = linkWithComparator ( h . root , root ) ; } decreasePoolSize = h . decreasePoolSize ; h . decreasePoolSize = 0 ; decreasePoolMinPos = h . decreasePoolMinPos ; h . decreasePoolMinPos = 0 ; Node < K , V > [ ] tmp = decreasePool ; decreasePool = h . decreasePool ; h . decreasePool = tmp ; } else { h . consolidate ( ) ; if ( comparator == null ) { root = link ( h . root , root ) ; } else { root = linkWithComparator ( h . root , root ) ; } } size += h . size ; h . root = null ; h . size = 0 ; h . other = this ; }
{@inheritDoc}

This operation takes amortized zero cost.