mirror of
https://github.com/meilisearch/meilisearch.git
synced 2024-11-29 08:35:15 +08:00
feat: Rename registers methods of DistinctMap
This commit is contained in:
parent
5a2d8a2395
commit
d3a67476e0
@ -17,7 +17,7 @@ impl<K: Hash + Eq> DistinctMap<K> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
let seen = self.inner.entry(key).or_insert(0);
|
||||||
if *seen < self.limit {
|
if *seen < self.limit {
|
||||||
*seen += 1;
|
*seen += 1;
|
||||||
@ -28,7 +28,7 @@ impl<K: Hash + Eq> DistinctMap<K> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn accept_without_key(&mut self) -> bool {
|
pub fn register_without_key(&mut self) -> bool {
|
||||||
self.len += 1;
|
self.len += 1;
|
||||||
true
|
true
|
||||||
}
|
}
|
||||||
@ -46,20 +46,20 @@ mod tests {
|
|||||||
fn easy_distinct_map() {
|
fn easy_distinct_map() {
|
||||||
let mut map = DistinctMap::new(2);
|
let mut map = DistinctMap::new(2);
|
||||||
for x in &[1, 1, 1, 2, 3, 4, 5, 6, 6, 6, 6, 6] {
|
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);
|
assert_eq!(map.len(), 8);
|
||||||
|
|
||||||
let mut map = DistinctMap::new(2);
|
let mut map = DistinctMap::new(2);
|
||||||
assert_eq!(map.digest(1), true);
|
assert_eq!(map.register(1), true);
|
||||||
assert_eq!(map.digest(1), true);
|
assert_eq!(map.register(1), true);
|
||||||
assert_eq!(map.digest(1), false);
|
assert_eq!(map.register(1), false);
|
||||||
assert_eq!(map.digest(1), false);
|
assert_eq!(map.register(1), false);
|
||||||
|
|
||||||
assert_eq!(map.digest(2), true);
|
assert_eq!(map.register(2), true);
|
||||||
assert_eq!(map.digest(3), true);
|
assert_eq!(map.register(3), true);
|
||||||
assert_eq!(map.digest(2), true);
|
assert_eq!(map.register(2), true);
|
||||||
assert_eq!(map.digest(2), false);
|
assert_eq!(map.register(2), false);
|
||||||
|
|
||||||
assert_eq!(map.len(), 5);
|
assert_eq!(map.len(), 5);
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ fn split_whitespace_automatons(query: &str) -> Vec<DfaExt> {
|
|||||||
let mut words = query.split_whitespace().map(str::to_lowercase).peekable();
|
let mut words = query.split_whitespace().map(str::to_lowercase).peekable();
|
||||||
|
|
||||||
while let Some(word) = words.next() {
|
while let Some(word) = words.next() {
|
||||||
|
|
||||||
let has_following_word = words.peek().is_some();
|
let has_following_word = words.peek().is_some();
|
||||||
let lev = if has_following_word || has_end_whitespace {
|
let lev = if has_following_word || has_end_whitespace {
|
||||||
automaton::build_dfa(&word)
|
automaton::build_dfa(&word)
|
||||||
@ -160,6 +159,12 @@ where D: Deref<Target=DB>,
|
|||||||
for group in tmp_groups {
|
for group in tmp_groups {
|
||||||
group.sort_unstable_by(|a, b| criterion.evaluate(a, b, view));
|
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 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);
|
groups.push(group);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -169,9 +174,9 @@ where D: Deref<Target=DB>,
|
|||||||
let mut seen = DistinctMap::new(self.size);
|
let mut seen = DistinctMap::new(self.size);
|
||||||
|
|
||||||
for document in documents {
|
for document in documents {
|
||||||
let accepted = match (self.function)(document.id, &self.inner.view) {
|
let accepted = match (self.function)(document.id, view) {
|
||||||
Some(key) => seen.digest(key),
|
Some(key) => seen.register(key),
|
||||||
None => seen.accept_without_key(),
|
None => seen.register_without_key(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if accepted {
|
if accepted {
|
||||||
|
Loading…
Reference in New Issue
Block a user