提交 86830355 编写于 作者: C CyrusNajmabadi

Use tuples in more cases.

上级 a4364cde
...@@ -113,16 +113,16 @@ private IEnumerable<T> GetInOrderIntervals(int start, int length, TestInterval t ...@@ -113,16 +113,16 @@ private IEnumerable<T> GetInOrderIntervals(int start, int length, TestInterval t
var end = start + length; var end = start + length;
// The bool indicates if this is the first time we are seeing the node. // The bool indicates if this is the first time we are seeing the node.
var candidates = new Stack<ValueTuple<Node, bool>>(); var candidates = new Stack<(Node node, bool firstTime)>();
candidates.Push(ValueTuple.Create(root, true)); candidates.Push((root, true));
while (candidates.Count > 0) while (candidates.Count > 0)
{ {
var currentTuple = candidates.Pop(); var currentTuple = candidates.Pop();
var currentNode = currentTuple.Item1; var currentNode = currentTuple.node;
Debug.Assert(currentNode != null); Debug.Assert(currentNode != null);
var firstTime = currentTuple.Item2; var firstTime = currentTuple.firstTime;
if (!firstTime) if (!firstTime)
{ {
...@@ -148,18 +148,18 @@ private IEnumerable<T> GetInOrderIntervals(int start, int length, TestInterval t ...@@ -148,18 +148,18 @@ private IEnumerable<T> GetInOrderIntervals(int start, int length, TestInterval t
var right = currentNode.Right; var right = currentNode.Right;
if (right != null && GetEnd(right.MaxEndNode.Value, introspector) >= start) if (right != null && GetEnd(right.MaxEndNode.Value, introspector) >= start)
{ {
candidates.Push(ValueTuple.Create(right, true)); candidates.Push((right, firstTime: true));
} }
} }
candidates.Push(ValueTuple.Create(currentNode, false)); candidates.Push((currentNode, firstTime: false));
// only if left's maxVal overlaps with interval's start, we should consider // only if left's maxVal overlaps with interval's start, we should consider
// left subtree // left subtree
var left = currentNode.Left; var left = currentNode.Left;
if (left != null && GetEnd(left.MaxEndNode.Value, introspector) >= start) if (left != null && GetEnd(left.MaxEndNode.Value, introspector) >= start)
{ {
candidates.Push(ValueTuple.Create(left, true)); candidates.Push((left, firstTime: true));
} }
} }
} }
...@@ -243,22 +243,22 @@ public IEnumerator<T> GetEnumerator() ...@@ -243,22 +243,22 @@ public IEnumerator<T> GetEnumerator()
} }
// The bool indicates if this is the first time we are seeing the node. // The bool indicates if this is the first time we are seeing the node.
var candidates = new Stack<ValueTuple<Node, bool>>(); var candidates = new Stack<(Node node, bool firstTime)>();
candidates.Push(ValueTuple.Create(root, true)); candidates.Push(ValueTuple.Create(root, true));
while (candidates.Count != 0) while (candidates.Count != 0)
{ {
var currentTuple = candidates.Pop(); var currentTuple = candidates.Pop();
var currentNode = currentTuple.Item1; var currentNode = currentTuple.node;
if (currentNode != null) if (currentNode != null)
{ {
if (currentTuple.Item2) if (currentTuple.firstTime)
{ {
// First time seeing this node. Mark that we've been seen and recurse // First time seeing this node. Mark that we've been seen and recurse
// down the left side. The next time we see this node we'll yield it // down the left side. The next time we see this node we'll yield it
// out. // out.
candidates.Push(ValueTuple.Create(currentNode.Right, true)); candidates.Push((currentNode.Right, firstTime: true));
candidates.Push(ValueTuple.Create(currentNode, false)); candidates.Push((currentNode, firstTime: false));
candidates.Push(ValueTuple.Create(currentNode.Left, true)); candidates.Push((currentNode.Left, firstTime: true));
} }
else else
{ {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册