Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Paul Masurel <[email protected]>
  • Loading branch information
PSeitz and fulmicoton authored Nov 12, 2024
1 parent 7235d4d commit 32b0d86
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/docset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,15 @@ pub trait DocSet: Send {
/// Implementations may choose to advance past the target if target does not exist.
///
/// DocSets that already have an efficient `seek` method don't need to implement `seek_exact`.
/// All wapper DocSets should forward `seek_exact` to the underlying DocSet.
/// All wrapper DocSets should forward `seek_exact` to the underlying DocSet.
///
/// ## API Behaviour
/// If `seek_exact` is returning true, a call to `doc()` has to return target.
/// If `seek_exact` is returning false, a call to `doc()` may return the previous doc,
/// which may be lower than target.
fn seek_exact(&mut self, target: DocId) -> bool {
let current_doc = self.doc();
if current_doc < target {
self.seek(target);
}
self.doc() == target
let doc = self.seek(target);
doc == target
}

/// Fills a given mutable buffer with the next doc ids from the
Expand Down
3 changes: 2 additions & 1 deletion src/query/size_hint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
/// The estimated number of documents in the intersection.
pub fn estimate_intersection<I>(mut docset_sizes: I, max_docs: u32) -> u32
where I: Iterator<Item = u32> {
if max_doc == 0u32 { return 0u32; }
// Terms tend to be not really randomly distributed.
// This factor is used to adjust the estimate.
let mut co_loc_factor: f64 = 1.3;
Expand Down Expand Up @@ -62,7 +63,7 @@ where I: Iterator<Item = u32> {

let union_estimate = (max_docs as f64 * (1.0 - not_in_any_set_prob)).round();

union_estimate.min(u32::MAX as f64) as u32
union_estimate.min(max_docs as f64) as u32
}

#[cfg(test)]
Expand Down

0 comments on commit 32b0d86

Please sign in to comment.