2024-05-06 20:49:45 +08:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use crate::{FieldId, Weight};
|
|
|
|
|
|
|
|
#[derive(Debug, Default, Serialize, Deserialize)]
|
|
|
|
pub struct FieldidsWeightsMap {
|
|
|
|
map: HashMap<FieldId, Weight>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FieldidsWeightsMap {
|
|
|
|
pub fn insert(&mut self, fid: FieldId, weight: Weight) -> Option<Weight> {
|
|
|
|
self.map.insert(fid, weight)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn remove(&mut self, fid: FieldId) -> Option<Weight> {
|
|
|
|
self.map.remove(&fid)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn weight(&self, fid: FieldId) -> Option<Weight> {
|
|
|
|
self.map.get(&fid).copied()
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn max_weight(&self) -> Option<Weight> {
|
|
|
|
self.map.values().copied().max()
|
|
|
|
}
|
2024-05-07 23:56:40 +08:00
|
|
|
|
|
|
|
pub fn ids<'a>(&'a self) -> impl Iterator<Item = FieldId> + 'a {
|
|
|
|
self.map.keys().copied()
|
|
|
|
}
|
2024-05-06 20:49:45 +08:00
|
|
|
}
|