Prefer summing the attribute

This commit is contained in:
Clément Renault 2019-12-11 18:37:26 +01:00
parent 86ee0cbd6e
commit d75339a271
No known key found for this signature in database
GPG Key ID: 0151CDAB43460DAE

View File

@ -1,4 +1,4 @@
use std::cmp::{self, Ordering}; use std::cmp::Ordering;
use compact_arena::SmallArena; use compact_arena::SmallArena;
use slice_group_by::GroupBy; use slice_group_by::GroupBy;
@ -32,16 +32,16 @@ impl Criterion for Attribute {
) -> Ordering ) -> Ordering
{ {
#[inline] #[inline]
fn best_attribute(matches: &[SimpleMatch]) -> u16 { fn sum_of_attribute(matches: &[SimpleMatch]) -> usize {
let mut best_attribute = u16::max_value(); let mut sum_of_attribute = 0;
for group in matches.linear_group_by_key(|bm| bm.query_index) { for group in matches.linear_group_by_key(|bm| bm.query_index) {
best_attribute = cmp::min(best_attribute, group[0].attribute); sum_of_attribute += group[0].attribute as usize;
} }
best_attribute sum_of_attribute
} }
let lhs = best_attribute(&lhs.processed_matches); let lhs = sum_of_attribute(&lhs.processed_matches);
let rhs = best_attribute(&rhs.processed_matches); let rhs = sum_of_attribute(&rhs.processed_matches);
lhs.cmp(&rhs) lhs.cmp(&rhs)
} }