All Downloads are FREE. Search and download functionalities are using the official Maven repository.

shz.core.queue.p.ConcurrentMaxPQueue Maven / Gradle / Ivy

There is a newer version: 2024.0.2
Show newest version
package shz.core.queue.p;

import java.util.Comparator;

public final class ConcurrentMaxPQueue extends ConcurrentRBBSTPQueue {
    private static final long serialVersionUID = -5074168243264342412L;

    public ConcurrentMaxPQueue(Comparator comparator) {
        super(comparator);
    }

    public static  ConcurrentMaxPQueue of(Comparator comparator) {
        return new ConcurrentMaxPQueue<>(comparator);
    }

    @Override
    protected E peek0() {
        if (root == null) return null;
        Node h = root;
        while (h.right != null) h = h.right;
        return h.e;
    }

    @Override
    protected Node delTop(Node h) {
        if (isRed(h.left)) h = rotateRight(h);
        if (h.right == null) return h.left;
        if (!isRed(h.right) && !isRed(h.right.left)) h = moveRedRight(h);
        h.right = delTop(h.right);
        return balance(h);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy