internal int ComparePriority(GenericHeapElementWithTimestamp <T> other) { var cmp = base.priority.CompareTo(other.priority); // Consider a more recent sequence to have a lower priority value (== higher priority) // so reverse the direction of comparison. Note: Timestamp only applies in the case // of tied priorities, so if it wraps, we'll have suboptimal processing and likely a different // path in the event of ties, but will not fail. return((cmp != 0) ? cmp : other.Timestamp.CompareTo(this.Timestamp)); }
internal void Enqueue(T element, double priority) { if (heapSize == A.Length - 1) { var newA = new GenericHeapElementWithTimestamp <T> [A.Length * 2]; Array.Copy(A, 1, newA, 1, heapSize); A = newA; } heapSize++; int i = heapSize; GenericHeapElementWithTimestamp <T> h; A[i] = cache[element] = h = new GenericHeapElementWithTimestamp <T>(i, priority, element, this.NextTimestamp); while (i > 1 && A[i >> 1].ComparePriority(A[i]) > 0) { SwapWithParent(i); i >>= 1; } System.Diagnostics.Debug.Assert(A[i] == h); A[i] = h; }
void PutAtI(int i, GenericHeapElementWithTimestamp <T> h) { A[i] = h; h.indexToA = i; }