System.IComparable.CompareTo(I)

Here are the examples of the csharp api System.IComparable.CompareTo(I) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

4 Examples 7

19 Source : HeapPriorityQueue.cs
with BSD 2-Clause "Simplified" License
from SFraissTU

public override void Remove(T element, I priority) {
            lock (locker) {
                if (count == 0) return;
                //Suche nach Priority -> ermöglicht überspringen von Teilbäumen
                Queue<int> indizesToCheck = new Queue<int>();
                indizesToCheck.Enqueue(0);
                while (indizesToCheck.Count != 0) {
                    int i = indizesToCheck.Dequeue();
                    Entry entry = heapArray[i];
                    if (entry.priority.Equals(priority) && entry.element.Equals(element)) {
                        RemoveByArrayIndex(i);
                        return;
                    } else {
                        //Wenn die Kinder kleiner als der gewünschte Index sind, brauchen sie nicht mehr angesehen zu werden
                        if (i * 2 < count && heapArray[i * 2].priority.CompareTo(priority) >= 0) {
                            indizesToCheck.Enqueue(i * 2);
                        }
                        if (i * 2 + 1 < count && heapArray[i * 2 + 1].priority.CompareTo(priority) >= 0) {
                            indizesToCheck.Enqueue(i * 2 + 1);
                        }
                    }
                }
            }
        }

19 Source : HeapPriorityQueue.cs
with BSD 2-Clause "Simplified" License
from SFraissTU

private void RemoveByArrayIndex(int i) {
            int lastIdx = count - 1;
            Swap(lastIdx, i);
            count--;
            if (i != lastIdx) {
                //Wenn Root oder Parent größer ist (wies sein soll) -> checken nach unten
                if (i == 0 || heapArray[i].priority.CompareTo(heapArray[i / 2].priority) < 0) {
                    HeapifyDown(i);
                } else {
                    HeapifyUp(i);
                }
            }
        }

19 Source : HeapPriorityQueue.cs
with BSD 2-Clause "Simplified" License
from SFraissTU

private void HeapifyDown(int currentindex) {
            int i = currentindex;
            while (2 * i < count) {
                //heapArray[i] hat ein linkes Kind (heapArray[j])
                int j = 2 * i;
                if (j < count - 1) {
                    //heapArray[i] hat ein rechtes Kind (heapArray[j+1])
                    if (heapArray[j].priority.CompareTo(heapArray[j + 1].priority) < 0) {
                        j = j + 1;
                    }
                }
                //j ist der Index des größeren Kindes. Mit diesem muss getauscht werden, falls Heap-Bedingung verletzt (i < j)
                if (heapArray[i].priority.CompareTo(heapArray[j].priority) < 0) {
                    Swap(i, j);
                    i = j;
                } else {
                    i = count; // Finished
                }
            }
        }

19 Source : HeapPriorityQueue.cs
with BSD 2-Clause "Simplified" License
from SFraissTU

private void HeapifyUp(int currentindex) {
            int parentindex = (currentindex) / 2;
            while (currentindex > 0 && heapArray[currentindex].priority.CompareTo(heapArray[parentindex].priority) > 0) {
                Swap(currentindex, parentindex);
                currentindex = parentindex;
                parentindex = parentindex / 2;
            }
        }