Ejemplo n.º 1
0
        public void IntensiveEditingSession()
        {
            var table = PieceTable.ForArray(new int[0]);

            const int iterations             = 10 * 1000;
            const int insertionsPerIteration = 30;
            const int deletionsPerIteration  = 2;

            var random    = new Randomizer(42);
            var totalTime = BenchmarkIterations(iterations, delegate
            {
                var insertionPoint = random.Next(table.Length);
                for (var i = 0; i < insertionsPerIteration; ++i)
                {
                    table = table.Insert(insertionPoint + i, i);
                }

                var readPosition = random.Next(table.Length);
                table.ToArray(readPosition, Math.Min(table.Length - readPosition, insertionsPerIteration));

                for (var i = 0; i < deletionsPerIteration; ++i)
                {
                    table = table.Delete(random.Next(table.Length), 1);
                }
            });

            const int totalNumberOfOperations = iterations * (insertionsPerIteration + deletionsPerIteration);

            ReportTotalNumberOfOperations(totalTime, totalNumberOfOperations);
            Assert.AreEqual(iterations * insertionsPerIteration - iterations * deletionsPerIteration, table.Length);
        }
Ejemplo n.º 2
0
        private static PieceTable <int> CreateTableWithManyPieces(int length)
        {
            var table = PieceTable.ForArray(new int[0]);

            for (var i = 0; i < length; ++i)
            {
                table = table.Insert(0, i);
            }
            return(table);
        }
Ejemplo n.º 3
0
 public TextSnapshotLines(PieceTable <char> text)
 {
     _spans = PieceTable.ForArray(LineParser.LineSpansFor(text).ToArray());
 }