예제 #1
0
        private void WritePartition(bool collectGarbage = true)
        {
            var partitionName = CreatePartitionName(_nextPartitionNumber++);

            using (var writer = new StreamWriter(partitionName, false, Encoding.UTF8, Constants.StreamWriterBuffer))
            {
                var orderedEntries = _buffer
                                     .AsParallel()
                                     .OrderBy(entry => entry);

                var firstEntry = true;
                foreach (var entry in orderedEntries)
                {
                    if (firstEntry)
                    {
                        firstEntry = false;
                    }
                    else
                    {
                        writer.WriteLine();
                    }

                    writer.WriteLine(entry.Key.Span);

                    entry.Sort();
                    var firstNumber = true;
                    foreach (var number in entry)
                    {
                        if (firstNumber)
                        {
                            firstNumber = false;
                        }
                        else
                        {
                            writer.Write('|');
                        }

                        writer.WriteLong(number);
                    }
                }
            }

            _buffer.Clear();

            if (collectGarbage)
            {
                GC.Collect();
            }
        }