public static void Sort <T, V>(T[] keys, V[] values, System.Collections.Generic.IComparer <T> comparer = null) { if (comparer == null) { comparer = System.Collections.Generic.Comparer <T> .Default; } #if !WINRT && !PORTABLE Array.Sort(keys, values, comparer); #else // bubble-sort; it'll work on MF, has small code, // and works well-enough for our sizes. This approach // also allows us to do `int` compares without having // to go via IComparable etc, so win:win bool swapped; do { swapped = false; for (int i = 1; i < keys.Length; i++) { if (comparer.Compare(keys[i - 1], keys[i]) > 0) { var tmpKey = keys[i]; keys[i] = keys[i - 1]; keys[i - 1] = tmpKey; var tmpValue = values[i]; values[i] = values[i - 1]; values[i - 1] = tmpValue; swapped = true; } } } while (swapped); #endif }
public override void Enqueue(T item) { int pos = 0; while (pos + 1 <= Count && _comparer.Compare(this[pos], item) < 0) { pos++; } base.Insert(pos, item); }
public int Compare(T x, T y) { return(comparer.Compare(x, y)); }
public int Compare(BTreeItem <TKey, TValue> x, BTreeItem <TKey, TValue> y) { return(KeyComparer.Compare(x.Key, y.Key)); }