Exemplo n.º 1
0
        public void CorrectlyMergesMultipleSortedEnumerators()
        {
            var seq1 = new[] { 10, 7, 1 };
            var seq2 = new[] { 12, 8, 1 };
            var seq3 = new[] { 9, 5, 4 };

            var sequenceEnumerators = new[] { seq1, seq2, seq3 }
            .Select(seq => ((IEnumerable <int>)seq).GetEnumerator())
            .ToArray();

            KWayMerge <int> sut = new KWayMerge <int>(sequenceEnumerators, (x, y) => x > y);

            int[] actual = sut.Execute().ToArray();

            CollectionAssert.AreEqual(new[] { 12, 10, 9, 8, 7, 5, 4, 1, 1 }, actual);
        }
Exemplo n.º 2
0
        private Task MergePartitionDictionariesIntoOutputQueue(
            IEnumerable <WordWithCount>[] partitionDicts,
            BlockingCollection <WordWithCount> outputQueue)
        {
            return(Task.Run(() =>
            {
                try
                {
                    var partitionEnumerators = partitionDicts.Select(pd => pd.GetEnumerator()).ToArray();
                    var kwayMerge = new KWayMerge <WordWithCount>(partitionEnumerators, WordGreatherThanFunc);

                    foreach (WordWithCount wordWithCount in kwayMerge.Execute())
                    {
                        outputQueue.Add(wordWithCount);
                    }
                }
                finally
                {
                    outputQueue.CompleteAdding();
                }
            }));
        }
        private void MergeChunksAsync(string destPath, ICollection <string> chunkPaths)
        {
            var bufferSize = Math.Max(4096, _chunkSizeBytes / chunkPaths.Count);

            KWayMerge.Execute(chunkPaths, destPath, bufferSize);
        }