Esempio n. 1
0
        /// <summary>
        /// Inserts a new element in a sorted collection
        /// </summary>
        /// <typeparam name="TC"></typeparam>
        /// <typeparam name="TI"></typeparam>
        /// <param name="col"></param>
        /// <param name="item"></param>
        /// <param name="comparer"></param>
        public static void InsertSorted <TC>(this Collection <TC> collection, TC item, System.Collections.Generic.IComparer <TC> comparer)
        {
            // Find right position and insert
            int i = 0;

            for (; i < collection.Count(); ++i)
            {
                if (comparer.Compare(item, collection.ElementAt(i)) < 0)
                {
                    break;
                }
            }

            // Not yet inserted, insert at the end
            collection.Insert(i, item);
        }
Esempio n. 2
0
 public int Compare(BTreeItem <TKey, TValue> x, BTreeItem <TKey, TValue> y)
 {
     return(KeyComparer.Compare(x.Key, y.Key));
 }
Esempio n. 3
0
 /// <summary>
 /// Compare two entries
 /// </summary>
 /// <param name="entry1">First entry</param>
 /// <param name="entry2">Second entry</param>
 /// <returns>The result of comparing the keys</returns>
 public int Compare(System.Collections.Generic.KeyValuePair <K, V> entry1, System.Collections.Generic.KeyValuePair <K, V> entry2)
 {
     return(comparer.Compare(entry1.Key, entry2.Key));
 }
Esempio n. 4
0
 /// <summary>
 /// Compare two entries
 /// </summary>
 /// <param name="entry1">First entry</param>
 /// <param name="entry2">Second entry</param>
 /// <returns>The result of comparing the keys</returns>
 public int Compare(KeyValuePair <K, V> entry1, KeyValuePair <K, V> entry2)
 {
     return(comparer.Compare(entry1.Key, entry2.Key));
 }