@@ -0,0 +1,1156 @@
+package com.janosgyerik.tools.collections;%0A%0Aimport java.util.Comparator;%0Aimport java.util.HashMap;%0Aimport java.util.Map;%0Aimport java.util.PriorityQueue;%0A%0Apublic class UpdatableHeap%3CT%3E %7B%0A%0A  private final PriorityQueue%3CNode%3CT%3E%3E pq = new PriorityQueue%3C%3E(Comparator.comparingInt(node -%3E node.priority));%0A  private final Map%3CT, Node%3CT%3E%3E entries = new HashMap%3C%3E();%0A%0A  public void addOrUpdate(T value, int priority) %7B%0A    if (entries.containsKey(value)) %7B%0A      entries.remove(value).removed = true;%0A    %7D%0A%0A    Node%3CT%3E node = new Node%3C%3E(value, priority);%0A    entries.put(value, node);%0A    pq.add(node);%0A  %7D%0A%0A  public T pop() %7B%0A    while (!pq.isEmpty()) %7B%0A      Node%3CT%3E node = pq.poll();%0A      if (!node.removed) %7B%0A        entries.remove(node.value);%0A        return node.value;%0A      %7D%0A    %7D%0A%0A    throw new IllegalStateException(%22pop from empty heap%22);%0A  %7D%0A%0A  public boolean isEmpty() %7B%0A    return entries.isEmpty();%0A  %7D%0A%0A  private static class Node%3CT%3E %7B%0A    private final T value;%0A    private final int priority;%0A    private boolean removed = false;%0A%0A    private Node(T value, int priority) %7B%0A      this.value = value;%0A      this.priority = priority;%0A    %7D%0A  %7D%0A%7D%0A

Add UpdatableHeap