public void DecreaseKey_WhenIndexIsInQueue_WillChangeOldKeyToNewSmallerKey() { IndexMinPriorityQueue <double> queue = new IndexMinPriorityQueue <double>(10); queue.Insert(4, 12.5); queue.Insert(3, 40.12); queue.Insert(7, 4.3); queue.Insert(2, 162.75); double newKey = 5.54; queue.DecreaseKey(3, newKey); double keyAtIndex = queue.KeyAt(3); Assert.AreEqual(newKey, keyAtIndex); }
private void Relax(DirectedEdge edge) { uint v = edge.From; uint w = edge.To; if (_distanceTo[w] > _distanceTo[v] + edge.Weight) { _distanceTo[w] = _distanceTo[v] + edge.Weight; _edgeTo[w] = edge; if (_priorityQueue.Contains((int)w)) { _priorityQueue.DecreaseKey((int)w, _distanceTo[w]); } else { _priorityQueue.Insert((int)w, _distanceTo[w]); } } }