private void MergePartialIndexes()
		{
			for (int index = 0; index < _indexes.Count; index++)
			{
				var partialReaders = _options.GetAllPartialsFor(index)
					.Select(x => new SourceReader(x, _options.Encoding, new[] { 0, 1 }).ReadFromStream().GetEnumerator())
					.ToList();

				var heap = new Heap<HeapEntry>(partialReaders.Count, (x, y) => Utils.CompareIndexEntries(x.IndexEntry, y.IndexEntry));
				for (int i = 0; i < partialReaders.Count; i++)
				{
					var reader = partialReaders[i];
					if (reader.MoveNext() == false) // empty reader?
						continue;
					var heapEntry = new HeapEntry
					{
						Index = index,
						Reader = reader,
						IndexEntry = ReadIndexEntry(reader)
					};
					heap.Enqueue(heapEntry);
				}

				using (var stream = _options.Create(index))
				using (var builder = new IndexBuilder(stream, _options.Encoding))
				{
					while (heap.Count > 0)
					{
						var heapEntry = heap.Dequeue();
						builder.Add(heapEntry.IndexEntry);
						if (heapEntry.Reader.MoveNext() == false)
							continue;
						heapEntry.IndexEntry = ReadIndexEntry(heapEntry.Reader);
						heap.Enqueue(heapEntry);
					}
				}

				_options.DeleteAllPartialsFor(index);
			}
		}
		private void FlushIntermediateIndexes()
		{
			for (int index = 0; index < _indexes.Count; index++)
			{
				var indexState = _indexes[index];
				indexState.Values.Sort(Utils.CompareIndexEntries);
				indexState.Counter++;
				using (var stream = _options.CreatePartial(index, indexState.Counter))
				using (var indexBuilder = new IndexBuilder(stream, _options.Encoding))
				{
					foreach (var indexEntry in indexState.Values)
					{
						indexBuilder.Add(indexEntry);
						_pool.Return(indexEntry.Value.Array);
					}
					indexState.Values.Clear();
				}
			}
		}