Skip to content

Commit

Permalink
Merge pull request #4 from pmcgleenon/optimizations
Browse files Browse the repository at this point in the history
optimization - skip min-heap stuff if this item's count is lower than min
  • Loading branch information
pmcgleenon authored Jun 19, 2024
2 parents 4ce881a + 4537b2a commit 4a8e4fe
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/heavykeeper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,13 @@ impl<T: Ord + Clone + Hash + Debug> TopK<T> {
}

let space_in_heap = self.priority_queue.len() < self.top_items;
let new_max = max_count >= self.priority_queue.peek().map_or(0, |v| v.1 .0);
let curr_min = self.priority_queue.peek().map_or(0, |v| v.1 .0);
// skip if max_count is less than the smallest count in the min-heap
if max_count < curr_min && !space_in_heap {
return;
}

let new_max = max_count >= curr_min;

if self.priority_queue.get(&item).is_some() {
self.priority_queue.change_priority(&item, Reverse(max_count));
Expand Down

0 comments on commit 4a8e4fe

Please sign in to comment.