compressed_set/
utils.rs

1use std::collections::HashMap;
2
3/// Returns the most frequent step size in the given set
4#[inline]
5pub fn max_step_size(list: &[u32]) -> u32 {
6    get_steps_freq(list)
7        .iter()
8        .max_by(|a, b| a.1.cmp(&b.1))
9        .map(|i| *i.0)
10        .unwrap_or(1)
11}
12
13/// Returns the most frequent step sizes in the given set
14pub fn get_steps_freq(list: &[u32]) -> HashMap<u32, u32> {
15    let mut step_size_freq: HashMap<u32, u32> = HashMap::new();
16    for (b, a) in list.iter().zip(list.iter().skip(1)) {
17        *step_size_freq.entry(a - b).or_default() += 1;
18    }
19    step_size_freq
20}