Function
find_nearest
(enc: &[(f64, char)], value: f64)
Source from the content-addressed store, hash-verified
| 478 | } |
| 479 | |
| 480 | fn find_nearest(enc: &[(f64, char)], value: f64) -> Option<char> { |
| 481 | let mut best = None; |
| 482 | let mut dist = f64::INFINITY; |
| 483 | for (k, c) in enc { |
| 484 | let d = (k - value).abs(); |
| 485 | if d < dist { |
| 486 | dist = d; |
| 487 | best = Some(*c); |
| 488 | } |
| 489 | } |
| 490 | best |
| 491 | } |
| 492 | |
| 493 | pub fn encode_array(array: &[f64], encoding: &[(f64, char)]) -> String { |
| 494 | let mut s = String::new(); |
Tested by
no test coverage detected