@@ -711,7 +711,9 @@ SearchableLiveBucketListSnapshot::scanForEntriesOfType(
711711namespace
712712{
713713// Iterator for `BucketEntry`s of a given type in a bucket. Expects the stream
714- // to be positioned at the start of the type range.
714+ // to be positioned at the start of the type range. This is basically the same
715+ // as SearchableLiveBucketListSnapshot::scanForEntriesOfType's scanBucket except
716+ // with more control over when iteration happens.
715717class BucketEntryIterator
716718{
717719 BucketEntry mEntry ;
@@ -767,6 +769,7 @@ SearchableLiveBucketListSnapshot::scanForLiveEntriesOfType(
767769 LedgerEntryType type,
768770 std::function<void (LedgerEntry const &, LedgerKey const &)> callback) const
769771{
772+ ZoneScoped;
770773 // We implement this as a k-way merge over all buckets. We use a loser tree
771774 // for this. The benefit over a heap is ~2x fewer comparisons. A loser tree
772775 // is like a single-elimination tournament. The leaves of the tree are the
@@ -869,6 +872,7 @@ SearchableLiveBucketListSnapshot::scanForLiveEntriesOfType(
869872 {
870873 int index = tree[0 ];
871874 auto & iter = iterators[index];
875+ // Deduplicate entries with the same key across buckets
872876 if (auto & key = iter.getKey (); first || key != last)
873877 {
874878 last = key;
@@ -886,6 +890,7 @@ SearchableLiveBucketListSnapshot::scanForLiveEntriesOfType(
886890 }
887891 int winner = tree[index + numIterators];
888892
893+ // Update tournament up the tree to the root
889894 int i = (index + numIterators) / 2 ;
890895 while (i > 0 )
891896 {
0 commit comments