diff --git a/BTree.cs b/BTree.cs index d3c89ec..0f5c2ba 100644 --- a/BTree.cs +++ b/BTree.cs @@ -259,44 +259,49 @@ namespace ln.collections return false; } - public K PreviousOrCurrent(K current) - { - if (!TryGetPreviousOrCurrent(current, out K previousOrCurrent)) - throw new KeyNotFoundException(); - return previousOrCurrent; + public K PreviousOrCurrent(K current) + { + if (!TryGetPreviousOrCurrent(current, out K previousOrCurrent)) + throw new KeyNotFoundException(); + return previousOrCurrent; + } + public bool TryGetPreviousOrCurrent(K current, out K previousOrCurrent) + { + if (Empty) + { + previousOrCurrent = default(K); + return false; + } + + TreeNode next = FindFirstGE(current); + if (next == null) + previousOrCurrent = Last(); + else + previousOrCurrent = Previous(next).Key; + + return true; + } + public bool TryGetPreviousOrCurrentValue(K current, out V previousOrCurrentValue) + { + if (Empty) + { + previousOrCurrentValue = default(V); + return false; + } + + TreeNode next = FindFirstGE(current); + if (next == null) + previousOrCurrentValue = LastValue(); + else + { + TreeNode previousNode = Previous(next); + if (previousNode == null) + previousOrCurrentValue = FirstValue(); + else + previousOrCurrentValue = previousNode.Value; + } + return true; } - public bool TryGetPreviousOrCurrent(K current, out K previousOrCurrent) - { - if (Empty) - { - previousOrCurrent = default(K); - return false; - } - - TreeNode next = FindFirstGE(current); - if (next == null) - previousOrCurrent = Last(); - else - previousOrCurrent = Previous(next).Key; - - return true; - } - public bool TryGetPreviousOrCurrentValue(K current, out V previousOrCurrentValue) - { - if (Empty) - { - previousOrCurrentValue = default(V); - return false; - } - - TreeNode next = FindFirstGE(current); - if (next == null) - previousOrCurrentValue = LastValue(); - else - previousOrCurrentValue = Previous(next).Value; - - return true; - } diff --git a/ln.collections.csproj b/ln.collections.csproj index 5f98043..d3fb484 100644 --- a/ln.collections.csproj +++ b/ln.collections.csproj @@ -1,7 +1,13 @@ - netcoreapp2.1 + netcoreapp3.1 + true + 0.1.1 + Harald Wolff-Thobaben + l--n.de + 0.0.1.1 + 0.0.1.1