Skip to content

Commit

Permalink
fenwick tree for faster sampling
Browse files Browse the repository at this point in the history
  • Loading branch information
alexandres committed Feb 7, 2022
1 parent e85d23a commit c5d520c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions terashuf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ int main()
linesRemainingPerFile.push_back(file.lines);
}

auto sumHeap = FenwickTree(linesRemainingPerFile);
auto fenwickTree = FenwickTree(linesRemainingPerFile);

ll totalBytesWritten = 0, linesRemaining = totalLinesRead, totalBytesWrittenForProgress = 0;

Expand All @@ -333,8 +333,8 @@ int main()
while (linesRemaining)
{
ll randLine = std::uniform_int_distribution<ll>{0, linesRemaining - 1}(rng);
auto fileIdx = sumHeap.findIndexAndDraw(randLine + 1);
auto linesRemainingInFile = sumHeap.getCountAtIndex(fileIdx);
auto fileIdx = fenwickTree.findIndexAndDraw(randLine + 1);
auto linesRemainingInFile = fenwickTree.getCountAtIndex(fileIdx);
linesRemaining--;
TmpFile &file = files[fileIdx];
ll bytesRead = readLine(buf, sep, file);
Expand Down

0 comments on commit c5d520c

Please sign in to comment.