Added BTree.PreviousOrCurrent* method family
parent
d07d0e3dae
commit
21519c831c
38
BTree.cs
38
BTree.cs
|
@ -259,6 +259,44 @@ namespace ln.collections
|
|||
return false;
|
||||
}
|
||||
|
||||
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
|
||||
previousOrCurrentValue = Previous(next).Value;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue