Fix NullReferenceException in BTree.TryGetPreviousOrCurrentValue(..)
parent
21519c831c
commit
93b916b48c
79
BTree.cs
79
BTree.cs
|
@ -259,44 +259,49 @@ namespace ln.collections
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public K PreviousOrCurrent(K current)
|
public K PreviousOrCurrent(K current)
|
||||||
{
|
{
|
||||||
if (!TryGetPreviousOrCurrent(current, out K previousOrCurrent))
|
if (!TryGetPreviousOrCurrent(current, out K previousOrCurrent))
|
||||||
throw new KeyNotFoundException();
|
throw new KeyNotFoundException();
|
||||||
return previousOrCurrent;
|
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,13 @@
|
||||||
<Project Sdk="Microsoft.NET.Sdk">
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
<PropertyGroup>
|
<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>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|
Loading…
Reference in New Issue