fix: Allow documents to bypass attribute distinction

In situations where the attribute is not present.
This commit is contained in:
Clément Renault 2018-10-18 15:08:04 +02:00
parent 98899d3ea0
commit 86cb01b243

View File

@ -100,7 +100,7 @@ where C: Criterion
} }
pub fn retrieve_distinct_documents<K>(mut self, range: Range<usize>) -> Vec<Document> pub fn retrieve_distinct_documents<K>(mut self, range: Range<usize>) -> Vec<Document>
where F: Fn(&DocumentId) -> K, where F: Fn(&DocumentId) -> Option<K>,
K: Hash + Eq, K: Hash + Eq,
{ {
let mut documents = self.retrieve_all_documents(); let mut documents = self.retrieve_all_documents();
@ -122,8 +122,10 @@ where C: Criterion
let mut seen = DistinctMap::new(limit); let mut seen = DistinctMap::new(limit);
for document in documents { for document in documents {
let key = distinct(&document.id); let accepted = match distinct(&document.id) {
let accepted = seen.digest(key); Some(key) => seen.digest(key),
None => seen.accept_without_key(),
};
if accepted { if accepted {
if seen.len() == range.end { break } if seen.len() == range.end { break }
@ -154,7 +156,18 @@ impl<K: Hash + Eq> DistinctMap<K> {
pub fn digest(&mut self, key: K) -> bool { pub fn digest(&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 { *seen += 1; self.len += 1; true } else { false } if *seen < self.limit {
*seen += 1;
self.len += 1;
true
} else {
false
}
}
pub fn accept_without_key(&mut self) -> bool {
self.len += 1;
true
} }
pub fn len(&self) -> usize { pub fn len(&self) -> usize {