Skip to content

Commit

Permalink
implement #352
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-ha458 committed Sep 30, 2023
1 parent 4883a26 commit 6225a33
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/entity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,21 @@ 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 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 {
if mess_difference < 0.01 {
if coherence_difference > 0.02 {
return 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 {
if coherence_difference <= 0.02 {
return other
.multi_byte_usage()
.partial_cmp(&self.multi_byte_usage());
}
return coherence_b.partial_cmp(&coherence_a);
}
self.mean_mess_ratio.partial_cmp(&other.mean_mess_ratio)
}
Expand Down

0 comments on commit 6225a33

Please sign in to comment.