From d3a67476e0a6af2134554827f7397ac05b7ea4bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 13 Dec 2018 11:54:09 +0100 Subject: [PATCH] feat: Rename registers methods of DistinctMap --- src/rank/distinct_map.rs | 22 +++++++++++----------- src/rank/query_builder.rs | 13 +++++++++---- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/rank/distinct_map.rs b/src/rank/distinct_map.rs index 98a6947ad..b7a5edee3 100644 --- a/src/rank/distinct_map.rs +++ b/src/rank/distinct_map.rs @@ -17,7 +17,7 @@ impl DistinctMap { } } - pub fn digest(&mut self, key: K) -> bool { + pub fn register(&mut self, key: K) -> bool { let seen = self.inner.entry(key).or_insert(0); if *seen < self.limit { *seen += 1; @@ -28,7 +28,7 @@ impl DistinctMap { } } - pub fn accept_without_key(&mut self) -> bool { + pub fn register_without_key(&mut self) -> bool { self.len += 1; true } @@ -46,20 +46,20 @@ mod tests { fn easy_distinct_map() { let mut map = DistinctMap::new(2); for x in &[1, 1, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6] { - map.digest(x); + map.register(x); } assert_eq!(map.len(), 8); let mut map = DistinctMap::new(2); - assert_eq!(map.digest(1), true); - assert_eq!(map.digest(1), true); - assert_eq!(map.digest(1), false); - assert_eq!(map.digest(1), false); + assert_eq!(map.register(1), true); + assert_eq!(map.register(1), true); + assert_eq!(map.register(1), false); + assert_eq!(map.register(1), false); - assert_eq!(map.digest(2), true); - assert_eq!(map.digest(3), true); - assert_eq!(map.digest(2), true); - assert_eq!(map.digest(2), false); + assert_eq!(map.register(2), true); + assert_eq!(map.register(3), true); + assert_eq!(map.register(2), true); + assert_eq!(map.register(2), false); assert_eq!(map.len(), 5); } diff --git a/src/rank/query_builder.rs b/src/rank/query_builder.rs index 0e759adc5..0644d3a4d 100644 --- a/src/rank/query_builder.rs +++ b/src/rank/query_builder.rs @@ -21,7 +21,6 @@ fn split_whitespace_automatons(query: &str) -> Vec { let mut words = query.split_whitespace().map(str::to_lowercase).peekable(); while let Some(word) = words.next() { - let has_following_word = words.peek().is_some(); let lev = if has_following_word || has_end_whitespace { automaton::build_dfa(&word) @@ -160,6 +159,12 @@ where D: Deref, for group in tmp_groups { group.sort_unstable_by(|a, b| criterion.evaluate(a, b, view)); for group in GroupByMut::new(group, |a, b| criterion.eq(a, b, view)) { + for document in group.iter() { + match (self.function)(document.id, view) { + Some(key) => seen.register(key), + None => seen.register_without_key(), + }; + } groups.push(group); } } @@ -169,9 +174,9 @@ where D: Deref, let mut seen = DistinctMap::new(self.size); for document in documents { - let accepted = match (self.function)(document.id, &self.inner.view) { - Some(key) => seen.digest(key), - None => seen.accept_without_key(), + let accepted = match (self.function)(document.id, view) { + Some(key) => seen.register(key), + None => seen.register_without_key(), }; if accepted {