Пример #1
0
        /// <summary>
        /// Presorts the provided enumeration in batches and then performs an optimized insert on the resulting set(s).
        /// </summary>
        /// <param name="unorderedItems">The items to insert</param>
        /// <param name="allowUpdates">True to overwrite any existing records</param>
        /// <returns>The total number of records inserted or updated</returns>
        public int AddRange(IEnumerable <KeyValuePair <TKey, TValue> > unorderedItems, bool allowUpdates)
        {
            int total = 0;
            int count = 0;

            KeyValuePair <TKey, TValue>[]   items      = new KeyValuePair <TKey, TValue> [2048];
            KeyValueComparer <TKey, TValue> kvcomparer = new KeyValueComparer <TKey, TValue>(_keyComparer);

            foreach (KeyValuePair <TKey, TValue> item in unorderedItems)
            {
                if (count == 0x010000)
                {
                    MergeSort.Sort(items, kvcomparer);
                    total += AddRangeSorted(items, allowUpdates);
                    Array.Clear(items, 0, items.Length);
                    count = 0;
                }

                if (count == items.Length)
                {
                    Array.Resize(ref items, items.Length * 2);
                }
                items[count++] = item;
            }

            if (count > 0)
            {
                if (count != items.Length)
                {
                    Array.Resize(ref items, count);
                }

                MergeSort.Sort(items, kvcomparer);
                total += AddRangeSorted(items, allowUpdates);
            }
            return(total);
        }
Пример #2
0
        /// <summary>
        /// Merges n-number of ordered enumerations based on the comparer provided.
        /// </summary>
        public static IEnumerable <KeyValuePair <TKey, TValue> > Merge(IComparer <TKey> comparer, DuplicateHandling duplicateHandling, params IEnumerable <KeyValuePair <TKey, TValue> >[] enums)
        {
            KeyValueComparer <TKey, TValue> kvcompare = new KeyValueComparer <TKey, TValue>(comparer);

            return(WithDuplicateHandling(Merge(kvcompare, enums), kvcompare, duplicateHandling));
        }