From 7738a4028c167154c0c41da5281bbb566eee0e5b Mon Sep 17 00:00:00 2001 From: Harald Wolff Date: Thu, 1 Apr 2021 15:45:02 +0200 Subject: [PATCH] Added BTree.TryGetNextOrCurrent(), BTree.TryGetNextOrCurrentValue() --- ln.collections/BTree.cs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/ln.collections/BTree.cs b/ln.collections/BTree.cs index 0f5c2ba..ae613f2 100644 --- a/ln.collections/BTree.cs +++ b/ln.collections/BTree.cs @@ -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)