use std::collections::HashMap; use serde::{Deserialize, Serialize}; use crate::{FieldId, Weight}; #[derive(Debug, Default, Serialize, Deserialize)] pub struct FieldidsWeightsMap { map: HashMap, } impl FieldidsWeightsMap { pub fn insert(&mut self, fid: FieldId, weight: Weight) -> Option { self.map.insert(fid, weight) } pub fn remove(&mut self, fid: FieldId) -> Option { self.map.remove(&fid) } pub fn weight(&self, fid: FieldId) -> Option { self.map.get(&fid).copied() } pub fn max_weight(&self) -> Option { self.map.values().copied().max() } pub fn ids<'a>(&'a self) -> impl Iterator + 'a { self.map.keys().copied() } }