
shz.core.queue.p.ConcurrentMinPQueue Maven / Gradle / Ivy
package shz.core.queue.p;
import java.util.Comparator;
public final class ConcurrentMinPQueue extends ConcurrentRBBSTPQueue {
private ConcurrentMinPQueue(Comparator super E> comparator) {
super(comparator);
}
public static ConcurrentMinPQueue of(Comparator super E> comparator) {
return new ConcurrentMinPQueue<>(comparator);
}
@Override
public E peek() {
readLock.lock();
try {
if (root == null) return null;
Node h = root;
while (h.left != null) h = h.left;
return h.e;
} finally {
readLock.unlock();
}
}
@Override
protected Node delTop(Node h) {
if (h.left == null) return h.right;
if (!isRed(h.left) && !isRed(h.left.left)) h = moveRedLeft(h);
h.left = delTop(h.left);
return balance(h);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy