feat: Rename registers methods of DistinctMap

This commit is contained in:
Clément Renault 2018-12-13 11:54:09 +01:00
parent 5a2d8a2395
commit d3a67476e0
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE
2 changed files with 20 additions and 15 deletions

View File

@ -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);
if *seen < self.limit {
*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;
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);
}

View File

@ -21,7 +21,6 @@ fn split_whitespace_automatons(query: &str) -> Vec<DfaExt> {
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<Target=DB>,
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<Target=DB>,
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 {