mirror of
https://github.com/twitter/the-algorithm.git
synced 2025-06-22 20:48:16 -05:00
Twitter Recommendation Algorithm
Please note we have force-pushed a new initial commit in order to remove some publicly-available Twitter user information. Note that this process may be required in the future.
This commit is contained in:
45
navi/segdense/src/mapper.rs
Normal file
45
navi/segdense/src/mapper.rs
Normal file
@ -0,0 +1,45 @@
|
||||
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 {
|
||||
map: HashMap::new()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub trait MapWriter {
|
||||
fn set(&mut self, feature_id: i64, info: FeatureInfo);
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user