Skip to content

Commit

Permalink
Fixed bug where iterating over empty trees threw an exception
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexander-Sol committed Dec 17, 2022
1 parent cf45abb commit 41bde48
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions mzLib/MzLibUtil/TreeDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,9 @@ public void Delete(Node node)
Node inOrderSuccesor = GetInOrderSuccessor(node);
node.SwapKeyValuePair(inOrderSuccesor.Key, inOrderSuccesor.Value);
Delete(inOrderSuccesor);

} else if (node.parent.rightChild == node)

}
else if (node.parent.rightChild == node)
{
if (node.leftChild == null & node.rightChild == null)
{
Expand Down Expand Up @@ -199,7 +200,7 @@ internal static Node GetInOrderSuccessor(Node predeccesor)
if (predeccesor.rightChild != null)
{
return GetMinNode(predeccesor.rightChild);
}
}

Node parent = predeccesor.parent;
while (parent != null && predeccesor != parent.leftChild)
Expand All @@ -213,8 +214,9 @@ internal static Node GetInOrderSuccessor(Node predeccesor)

internal static Node GetMinNode(Node parent)
{
Node current = parent;
if (parent == null) return null;

Node current = parent;
while (current.leftChild != null)
{
current = current.leftChild;
Expand Down Expand Up @@ -297,7 +299,7 @@ public class TreeEnumerator : IEnumerator
public TreeEnumerator(Node root)
{
_rootNode = root;
_nextNode = SpectrumTree.GetMinNode(_rootNode);
_nextNode = _rootNode != null ? SpectrumTree.GetMinNode(_rootNode) : null;
}

public bool MoveNext()
Expand Down

0 comments on commit 41bde48

Please sign in to comment.