本文整理汇总了C#中RedBlackTree.MoveNext方法的典型用法代码示例。如果您正苦于以下问题:C# RedBlackTree.MoveNext方法的具体用法?C# RedBlackTree.MoveNext怎么用?C# RedBlackTree.MoveNext使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RedBlackTree
的用法示例。
在下文中一共展示了RedBlackTree.MoveNext方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetTextAt
public string GetTextAt (int offset, int count)
{
if (count <= 0 || this.Length == 0)
return "";
char[] result = new char[count];
RedBlackTree<TreeNode>.RedBlackTreeNode startNode = GetTreeNodeAtOffset (offset);
RedBlackTree<TreeNode>.RedBlackTreeNode endNode = GetTreeNodeAtOffset (offset + count);
int nodeOffset;
if (startNode == endNode) {
nodeOffset = CalcOffset (startNode);
startNode.value.CopyChars (this, nodeOffset, offset, count, result, 0);
} else {
RedBlackTree<TreeNode>.RedBlackTreeIterator iter = new RedBlackTree<TreeNode>.RedBlackTreeIterator (startNode);
RedBlackTree<TreeNode>.RedBlackTreeNode node;
int curOffset = 0;
do {
node = iter.CurrentNode;
nodeOffset = CalcOffset (node);
iter.MoveNext ();
if (node == null)
break;
int partLength;
if (node == startNode) {
partLength = nodeOffset + startNode.value.Length - offset;
} else if (node == endNode) {
partLength = offset + count - nodeOffset;
} else {
partLength = node.value.Length;
}
node.value.CopyChars (this, nodeOffset, offset + curOffset, partLength, result, curOffset);
curOffset += partLength;
} while (node != endNode);
}
return new string (result);
}
示例2: Remove
public void Remove (int offset, int length)
{
if (length <= 0 || this.Length == 0)
return;
RedBlackTree<TreeNode>.RedBlackTreeNode startNode = GetTreeNodeAtOffset (offset);
RedBlackTree<TreeNode>.RedBlackTreeNode endNode = GetTreeNodeAtOffset (offset + length);
int newLength = offset - CalcOffset (startNode);
if (startNode == endNode) {
TreeNode splittedNode = startNode.value.SplitRight (newLength + length);
ChangeLength (startNode, newLength);
if (splittedNode.Length > 0)
InsertAfter (startNode, splittedNode);
return;
}
int endSegmentLength = offset + length - CalcOffset (endNode);
RedBlackTree<TreeNode>.RedBlackTreeIterator iter = new RedBlackTree<TreeNode>.RedBlackTreeIterator (startNode);
RedBlackTree<TreeNode>.RedBlackTreeNode node;
do {
node = iter.CurrentNode;
iter.MoveNext ();
if (node == null)
break;
if (node == startNode) {
// has no right side, otherwise it would be startNode == endNode
length -= node.value.Length;
ChangeLength (node, newLength);
} else if (node == endNode) {
// has no left side, otherwise it would be startNode == endNode
TreeNode rightSide = node.value.SplitRight (endSegmentLength);
if (rightSide.Length > 0)
InsertAfter (node, rightSide);
RemoveNode (node);
} else { // nodes in between
length -= node.value.Length;
RemoveNode (node);
}
} while (node != endNode);
}