Skip to content

Commit

Permalink
Bugfix: Exception when merging with empty TDigest
Browse files Browse the repository at this point in the history
  • Loading branch information
ASolomatin committed Sep 8, 2023
1 parent 5f2bb51 commit 1d8da70
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/TDigestNet.Tests/TestMergeMultiple.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public class TestMergeMultiple : TestBase
private readonly TDigest _digestB = new();
private readonly TDigest _digestC = new();
private readonly TDigest _digestD = new();
private readonly TDigest _digestEmpty = new();
private readonly TDigest _merged;

public TestMergeMultiple()
Expand Down Expand Up @@ -42,7 +43,7 @@ public TestMergeMultiple()

_actual.Sort();

_merged = TDigest.MergeMultiple(_digestA, _digestB, _digestC, _digestD);
_merged = TDigest.MergeMultiple(_digestA, _digestB, _digestEmpty, _digestC, _digestD);
}

[Test, Order(0)]
Expand Down
11 changes: 3 additions & 8 deletions src/TDigestNet/TDigest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,8 @@ IEnumerable<Centroid> Enumerate()
var centroids = new Centroid?[enumeratorsCount];
try
{
for (int i = 0; i < enumeratorsCount;)
if (LoadValue(i))
i++;
for (int i = 0; i < enumeratorsCount; i++)
LoadValue(i);

while (enumeratorsLost != 0)
{
Expand Down Expand Up @@ -549,7 +548,7 @@ IEnumerable<Centroid> Enumerate()
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
bool LoadValue(int i)
void LoadValue(int i)
{
var enumerator = enumerators[i];

Expand All @@ -564,11 +563,7 @@ bool LoadValue(int i)
enumerators[i] = null;
centroids[i] = null;
enumeratorsLost--;

return false;
}

return true;
}
}
}
Expand Down

0 comments on commit 1d8da70

Please sign in to comment.