System.IComparable.CompareTo(U)

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

4 Examples 7

19 Source : PriorityQueue.cs
with GNU General Public License v3.0
from dd-bim

public T Dequeue(out U priority)
        {
            // replacedumes pq is not empty; up to calling code
            int li = this.data.Count - 1; // last index (before removal)
            var fronreplacedem = this.data[0];   // fetch the front
            this.data[0] = this.data[li];
            this.data.RemoveAt(li);

            --li; // last index (after removal)
            int pi = 0; // parent index. start at front of pq
            while(true)
            {
                int ci = (pi * 2) + 1; // left child index of parent
                if(ci > li)
                {
                    break;  // no children so done
                }

                int rc = ci + 1;     // right child
                if(rc <= li && this.data[rc].Priority.CompareTo(this.data[ci].Priority) < 0) // if there is a rc (ci + 1), and it is smaller than left child, use the rc instead
                {
                    ci = rc;
                }

                if(this.data[pi].Priority.CompareTo(this.data[ci].Priority) <= 0)
                {
                    break; // parent is smaller than (or equal to) smallest child so done
                }

                // swap parent and child
                var temp = this.data[ci];
                this.data[ci] = this.data[pi];
                this.data[pi] = temp;

                pi = ci;
            }
            priority = fronreplacedem.Priority;
            return fronreplacedem.Item;
        }

19 Source : PriorityQueue.cs
with GNU General Public License v3.0
from dd-bim

public void Enqueue(T item, U priority)
        {
            this.data.Add(new Tuple<T, U>(item, priority));
            int ci = this.data.Count - 1; // child index; start at end
            while(ci > 0)
            {
                int pi = (ci - 1) / 2; // parent index
                if(this.data[ci].Priority.CompareTo(this.data[pi].Priority) >= 0)
                {
                    break; // child item is larger than (or equal) parent so we're done
                }

                var temp = this.data[ci];
                this.data[ci] = this.data[pi];
                this.data[pi] = temp;
                ci = pi;
            }
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from silphid

public static T WithMin<T, U>(this IEnumerable<T> source, Func<T, IComparable<U>> selector)
        {
            var minElement = default(T);
            var minValue = default(IComparable<U>);

            foreach (var element in source)
            {
                var value = selector(element);
                if (Equals(minElement, default(T)) || value.CompareTo((U) minValue) < 0)
                {
                    minValue = value;
                    minElement = element;
                }
            }

            return minElement;
        }

19 Source : IEnumerableExtensions.cs
with MIT License
from silphid

public static T WithMax<T, U>(this IEnumerable<T> source, Func<T, IComparable<U>> selector)
        {
            var maxElement = default(T);
            var maxValue = default(IComparable<U>);

            foreach (var element in source)
            {
                var value = selector(element);
                if (Equals(maxElement, default(T)) || value.CompareTo((U) maxValue) > 0)
                {
                    maxValue = value;
                    maxElement = element;
                }
            }

            return maxElement;
        }