public void Split(int x, out Treap L, out Treap R) { Treap newTree = null; if (this.x <= x) { if (Right == null) { R = null; } else { Right.Split(x, out newTree, out R); } L = new Treap(this.x, y, Left, newTree); } else { if (Left == null) { L = null; } else { Left.Split(x, out L, out newTree); } R = new Treap(this.x, y, newTree, Right); } }
public void ReplaceMarks(TextOccurences occurences, int start, int end, int tailOffset) { if (occurences == null) { throw new ArgumentNullException("occurences"); } lock (_marksSyncRoot) { if (_positions == null) { ReplaceMarks(occurences); return; } Treap markThatContainsStart = FindMarkThatContainsPosition(_positions, start); if (markThatContainsStart != null) { start = markThatContainsStart.x; } Treap right = null; Treap garbage = null; _positions.Split(start - 1, out _positions, out right); if (right != null) { right.Split(end, out garbage, out right); } if (garbage != null) { garbage.ForEachInOrder(IncludeTextToScreenUpdate); } if (occurences != TextOccurences.Empty && occurences.Count > 0) { _markLength = occurences.TextLength; occurences.Positions.ForEachInOrder(IncludeTextToScreenUpdate); _positions = Treap.Merge(_positions, occurences.Positions); } if (right != null) { TreapBuilder shiftedMarks = new TreapBuilder(); right.ForEachInOrder((x) => { shiftedMarks.Add(x + tailOffset); }); _positions = Treap.Merge(_positions, shiftedMarks.ToTreap()); } } }