We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3181b52 commit 42e2decCopy full SHA for 42e2dec
app/lib/search/heap.dart
@@ -54,8 +54,9 @@ class _Heap<T> {
54
55
/// Builds a sorted list of the top-k items using the provided comparator.
56
///
57
-/// The algorithm uses min-heap to select the top-k items, and then builds
58
-/// a max-heap and uses heap sort to return the items in descending order.
+/// The algorithm collects all items, builds a max-heap in O(N) steps, and
+/// then selects the top-k items by removing the largest item from the heap
59
+/// and restoring the heap property again in O(k * log(N)) steps.
60
class TopKSortedListBuilder<T> {
61
final int _k;
62
final _Heap<T> _heap;
0 commit comments