Skip to content

Commit

Permalink
Merge pull request #21 from chris-ha458/unreachable_fix
Browse files Browse the repository at this point in the history
Fix #12
  • Loading branch information
nickspring authored Sep 30, 2023
2 parents 4883a26 + b5a4dab commit c260854
Showing 1 changed file with 8 additions and 12 deletions.
20 changes: 8 additions & 12 deletions src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,18 @@ impl PartialEq<Self> for CharsetMatch {

impl PartialOrd<Self> for CharsetMatch {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
let mess_difference = (self.mean_mess_ratio - other.mean_mess_ratio).abs();
let coherence_a = self.coherence();
let coherence_b = other.coherence();
let (coherence_a, coherence_b) = (self.coherence(), other.coherence());
let (multi_byte_a, multi_byte_b) = (self.multi_byte_usage(), other.multi_byte_usage());
let coherence_difference = (coherence_a - coherence_b).abs();
let mess_difference = (self.mean_mess_ratio - other.mean_mess_ratio).abs();

// Below 1% difference --> Use Coherence
if mess_difference < 0.01 && coherence_difference > 0.02 {
match (mess_difference < 0.01, coherence_difference > 0.02) {
(false, _) => self.mean_mess_ratio.partial_cmp(&other.mean_mess_ratio),
// Below 1% difference --> Use Coherence
(true, true) => coherence_b.partial_cmp(&coherence_a),
// When having a tough decision, use the result that decoded as many multi-byte as possible.
if mess_difference == 0.0 && coherence_difference == 0.0 {
return other
.multi_byte_usage()
.partial_cmp(&self.multi_byte_usage());
}
return coherence_b.partial_cmp(&coherence_a);
(true, false) => multi_byte_b.partial_cmp(&multi_byte_a),
}
self.mean_mess_ratio.partial_cmp(&other.mean_mess_ratio)
}
}

Expand Down

0 comments on commit c260854

Please sign in to comment.