Пример #1
0
 public Insertion(PieceTable <T> table, int position, T value)
 {
     _pieceIndex = table.PieceIndexForPosition(position);
     _table      = table;
     _position   = position;
     _value      = value;
     _pieceSpans = _table._pieceSpans;
     _pieceSpan  = _pieceSpans[_pieceIndex];
     _piece      = _pieceSpan.Piece;
 }
Пример #2
0
            PieceTable <T> InsertBySplitting()
            {
                var pieceStart        = _pieceSpan.Start;
                var positionInPiece   = _position - pieceStart;
                var parts             = _piece.SplitAt(positionInPiece);
                var replacementPieces = new[]
                {
                    PieceSpan.For(parts.First, pieceStart),
                    _table.NewSpanWith(_value, _position),
                    PieceSpan.For(parts.Second, _position + 1)
                };

                return(_table.ReplacePieceSpan(_pieceIndex, replacementPieces));
            }