use std::collections::HashMap;
#[derive(Clone, Default)]
pub struct BarcodeValue(HashMap<u32, u32>);
impl BarcodeValue {
pub fn new() -> Self {
Self::default()
}
pub fn setValue(&mut self, value: u32) {
self.0
.entry(value)
.and_modify(|confidence| *confidence += 1)
.or_insert(1);
}
pub fn getValue(&self) -> Vec<u32> {
let mut maxConfidence = -1_i32;
let mut result = Vec::new();
for (key, value) in &self.0 {
match (*value as i32).cmp(&maxConfidence) {
std::cmp::Ordering::Greater => {
maxConfidence = *value as i32;
result.clear();
result.push(*key);
}
std::cmp::Ordering::Equal => result.push(*key),
std::cmp::Ordering::Less => {}
}
}
result
}
pub fn getConfidence(&self, value: u32) -> u32 {
*self.0.get(&value).unwrap_or(&0)
}
}