Maxheap 与 priorityqueue 混淆

Maxheap vs priorityqueue confusion

假设我们要根据值对哈希图进行排序。我们实现了一个带有比较器的 priorityQueue 来做到这一点。因此,生成的 pq 从索引 0 到末尾从最大到最小排序。

代码如下:

PriorityQueue<Map.Entry<Integer, Integer>> pq = new PriorityQueue<Map.Entry<Integer, Integer>>(
                new Comparator<Map.Entry<Integer, Integer>>() {
                    @Override
                    public int compare(Entry<Integer, Integer> o1, Entry<Integer, Integer> o2) {
                        return o2.getValue() - o1.getValue();
                    }
                });

但是,有人说它是maxheap,我理解heap只是parent value大于child value,但我不明白为什么它是maxheap?它只是在 priorityQueue 中实现比较器?这与堆有什么关系?

java优先级队列的内部结构是堆。
此比较器将用于与优先级队列中的父值进行比较。