2023-04-01 00:36:31 +02:00
|
|
|
use std::collections::HashMap;
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub struct FeatureInfo {
|
|
|
|
pub tensor_index: i8,
|
|
|
|
pub index_within_tensor: i64,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub static NULL_INFO: FeatureInfo = FeatureInfo {
|
|
|
|
tensor_index: -1,
|
|
|
|
index_within_tensor: -1,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[derive(Debug, Default)]
|
|
|
|
pub struct FeatureMapper {
|
|
|
|
map: HashMap<i64, FeatureInfo>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl FeatureMapper {
|
|
|
|
pub fn new() -> FeatureMapper {
|
|
|
|
FeatureMapper {
|
2023-04-06 01:08:19 +02:00
|
|
|
map: HashMap::new(),
|
2023-04-01 00:36:31 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub trait MapWriter {
|
2023-04-06 01:08:19 +02:00
|
|
|
fn set(&mut self, feature_id: i64, info: FeatureInfo);
|
2023-04-01 00:36:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
pub trait MapReader {
|
|
|
|
fn get(&self, feature_id: &i64) -> Option<&FeatureInfo>;
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MapWriter for FeatureMapper {
|
|
|
|
fn set(&mut self, feature_id: i64, info: FeatureInfo) {
|
|
|
|
self.map.insert(feature_id, info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl MapReader for FeatureMapper {
|
|
|
|
fn get(&self, feature_id: &i64) -> Option<&FeatureInfo> {
|
|
|
|
self.map.get(feature_id)
|
|
|
|
}
|
|
|
|
}
|