Fix NullReferenceException in BTree.TryGetPreviousOrCurrentValue(..)

master
Harald Wolff 2020-11-24 14:50:09 +01:00
parent 21519c831c
commit 93b916b48c
2 changed files with 49 additions and 38 deletions

View File

@ -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;
}

View File

@ -1,7 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<TargetFramework>netcoreapp3.1</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>0.1.1</Version>
<Authors>Harald Wolff-Thobaben</Authors>
<Company>l--n.de</Company>
<AssemblyVersion>0.0.1.1</AssemblyVersion>
<FileVersion>0.0.1.1</FileVersion>
</PropertyGroup>
<ItemGroup>