From 32b0d86e81b196d84898f276f107379b5fc90e0a Mon Sep 17 00:00:00 2001 From: PSeitz Date: Tue, 12 Nov 2024 16:40:52 +0800 Subject: [PATCH] Apply suggestions from code review Co-authored-by: Paul Masurel --- src/docset.rs | 9 +++------ src/query/size_hint.rs | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/docset.rs b/src/docset.rs index 3030ff4b4b..2242c81ee0 100644 --- a/src/docset.rs +++ b/src/docset.rs @@ -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 diff --git a/src/query/size_hint.rs b/src/query/size_hint.rs index 9629bf69c4..310b02cc1d 100644 --- a/src/query/size_hint.rs +++ b/src/query/size_hint.rs @@ -10,6 +10,7 @@ /// The estimated number of documents in the intersection. pub fn estimate_intersection(mut docset_sizes: I, max_docs: u32) -> u32 where I: Iterator { + 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; @@ -62,7 +63,7 @@ where I: Iterator { 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)]