Approximate byte similarity in basis points (`0..=10_000`) (CB-9C). Import rename detection is heuristic evidence, so the score documents the basis rather than claiming a metric: byte-identical content scores full marks, differing content uses a common prefix+suffix ratio over the longer byte sequence. The multiply runs in widened `u64` (review CB-9C R4): a `u32` shared-bytes × 10,000 product ove
(old_bytes: &[u8], new_bytes: &[u8])
| 9465 | /// silent wrap in release — for supported inputs above ~429 KB, which the |
| 9466 | /// larger-file corpus requirement makes a normal case, not an exception. |
| 9467 | fn similarity_bps(old_bytes: &[u8], new_bytes: &[u8]) -> u16 { |
| 9468 | if old_bytes == new_bytes { |
| 9469 | return 10_000; |
| 9470 | } |
| 9471 | if old_bytes.is_empty() && new_bytes.is_empty() { |
| 9472 | return 10_000; |
| 9473 | } |
| 9474 | let common_prefix = old_bytes |
| 9475 | .iter() |
| 9476 | .zip(new_bytes.iter()) |
| 9477 | .take_while(|(a, b)| a == b) |
| 9478 | .count(); |
| 9479 | let common_suffix = old_bytes[common_prefix..] |
| 9480 | .iter() |
| 9481 | .rev() |
| 9482 | .zip(new_bytes[common_prefix.min(new_bytes.len())..].iter().rev()) |
| 9483 | .take_while(|(a, b)| a == b) |
| 9484 | .count(); |
| 9485 | let denominator = old_bytes.len().max(new_bytes.len()) as u64; |
| 9486 | let shared = (common_prefix + common_suffix).min(denominator as usize) as u64; |
| 9487 | |
| 9488 | if denominator == 0 { |
| 9489 | 10_000 |
| 9490 | } else { |
| 9491 | shared |
| 9492 | .checked_mul(10_000) |
| 9493 | .map(|scaled| (scaled / denominator).min(9_999) as u16) |
| 9494 | .unwrap_or(10_000) |
| 9495 | } |
| 9496 | } |
| 9497 | |
| 9498 | /// The graph-backed materialization (kind + mode) one canonical Git mode |
| 9499 | /// requires (CB-9C). Symlinks project the platform-independent `0o777` the |