Added BTree.TryGetNextOrCurrent(), BTree.TryGetNextOrCurrentValue()

master
Harald Wolff 2021-04-01 15:45:02 +02:00
parent aab19b5417
commit 7738a4028c
1 changed files with 37 additions and 0 deletions

View File

@ -303,6 +303,43 @@ namespace ln.collections
return true;
}
public bool TryGetNextOrCurrent(K current, out K nextOrCurrent)
{
if (Empty)
{
nextOrCurrent = default(K);
return false;
}
TreeNode next = FindFirstGE(current);
if (next == null)
{
nextOrCurrent = default(K);
return false;
}
nextOrCurrent = next.Key;
return true;
}
public bool TryGetNextOrCurrentValue(K current, out V nextOrCurrentValue)
{
if (Empty)
{
nextOrCurrentValue = default(V);
return false;
}
TreeNode next = FindFirstGE(current);
if (next == null)
{
nextOrCurrentValue = default(V);
return false;
}
nextOrCurrentValue = next.Value;
return true;
}
private TreeNode First(TreeNode node)