private void EnsureSorted() { var timer = Stopwatch.StartNew(); using var reader = new DataRecordReader(_options.Sorted); var charBuffer = new char[Constants.ValueMaxLength]; var counter = new Counter(); var fileLength = reader.Length; var readerPositionPrev = 0L; var repeatsCount = 0L; var dataRecordPrev = new DataRecord(long.MinValue, ReadOnlySpan <char> .Empty); foreach (var dataRecord in reader) { if (dataRecordPrev.CompareTo(dataRecord) == 1) { Console.WriteLine($"Not sorted data in line {counter.LinesCount}"); return; } var readerPosition = reader.Position; if (readerPosition - readerPositionPrev > Constants.HundredMegabytes) { ShowProgress(readerPosition, fileLength, timer.Elapsed.TotalSeconds); readerPositionPrev = readerPosition; } if (dataRecordPrev.Value.Equals(dataRecord.Value, Constants.ValueComparison)) { repeatsCount++; } counter.SetMinMax(dataRecord.Number); counter.IncrementLineCount(); dataRecordPrev = dataRecord.Copy(charBuffer); } Console.WriteLine(); Console.WriteLine("Data is really sorted"); Console.WriteLine($"Numbers between {counter.MinNumber} and {counter.MaxNumber}"); Console.WriteLine($"Lines count {counter.LinesCount}"); Console.WriteLine($"Repeats count {repeatsCount}"); }