@Override public boolean decreaseKey(E value, double priority) { /* * PriorityQueue does not support decreaseKey method. Therefore remove and re-add * the object. */ this.remove(value); return this.add(value, priority); }
/** * Changes the position of the given Node n in the pendingNodes queue and * updates its time and cost information. * * @param n * The Node that is revisited. * @param data * The data for n. * @param pendingNodes * The nodes visited and not processed yet. * @param time * The time of the visit of n. * @param cost * The accumulated cost at the time of the visit of n. * @param outLink * The link from which we came visiting n. */ void revisitNode(final Node n, final DijkstraNodeData data, final PseudoRemovePriorityQueue<Node> pendingNodes, final double time, final double cost, final Link outLink) { pendingNodes.remove(n); data.visit(outLink, cost, time, getIterationId()); pendingNodes.add(n, getPriority(data)); }
public void testIterator_ConcurrentModification_remove() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); Iterator<Integer> iter = pq.iterator(); assertTrue(iter.hasNext()); assertNotNull(iter.next()); assertTrue(pq.remove(Integer.valueOf(5))); assertTrue(iter.hasNext()); try { iter.next(); fail("missing ConcurrentModificationException"); } catch (ConcurrentModificationException e) { log.info("catched expected exception.", e); } iter = pq.iterator(); // but a new iterator must work again assertTrue(iter.hasNext()); assertNotNull(iter.next()); assertFalse(pq.remove(Integer.valueOf(5))); // cannot be removed, so it's no change assertTrue(iter.hasNext()); assertNotNull(iter.next()); }
public void testRemoveAndAdd_HigherPriority() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); assertEquals(3, pq.size()); // test removing an element and adding it with higher priority (=lower value) pq.remove(Integer.valueOf(5)); assertEquals(2, pq.size()); pq.add(Integer.valueOf(5), 2.5); assertEquals(3, pq.size()); assertEquals(Integer.valueOf(5), pq.poll()); assertEquals(Integer.valueOf(3), pq.poll()); assertEquals(Integer.valueOf(6), pq.poll()); assertNull(pq.poll()); }
public void testRemoveAndAdd_LowerPriority() { PseudoRemovePriorityQueue<Integer> pq = new PseudoRemovePriorityQueue<Integer>(10); pq.add(Integer.valueOf(5), 5.0); pq.add(Integer.valueOf(3), 3.0); pq.add(Integer.valueOf(6), 6.0); assertEquals(3, pq.size()); // test removing an element and adding it with lower priority (=higher value) pq.remove(Integer.valueOf(5)); assertEquals(2, pq.size()); pq.add(Integer.valueOf(5), 7.0); assertEquals(3, pq.size()); assertEquals(Integer.valueOf(3), pq.poll()); assertEquals(Integer.valueOf(6), pq.poll()); assertEquals(Integer.valueOf(5), pq.poll()); assertNull(pq.poll()); }
assertTrue(pq.remove(Integer.valueOf(5))); assertEquals(2, pq.size()); coll = getIteratorCollection(pq.iterator()); assertFalse(pq.remove(Integer.valueOf(5))); assertEquals(2, pq.size()); coll = getIteratorCollection(pq.iterator()); assertFalse(pq.remove(null)); assertEquals(2, pq.size()); coll = getIteratorCollection(pq.iterator());