Skip to content
Extraits de code Groupes Projets
Non vérifiée Valider 50090600 rédigé par Kubat's avatar Kubat
Parcourir les fichiers

UTILS: Update DKMap

parent e30e400d
Branches
Aucune étiquette associée trouvée
2 requêtes de fusion!205misc debug and harderning, mostly related to repo syncing,!197Draft: Refactor the whole code.
...@@ -7,12 +7,8 @@ use std::mem; ...@@ -7,12 +7,8 @@ use std::mem;
#[derive(Debug, Serialize, Deserialize, Default, Clone)] #[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct DKMap<K1: Hash + Eq, K2: Hash + Eq, Values> { pub struct DKMap<K1: Hash + Eq, K2: Hash + Eq, Values> {
#[serde(skip)]
primary_key_mapping: HashMap<K1, usize>, primary_key_mapping: HashMap<K1, usize>,
#[serde(skip)]
secondary_key_mapping: HashMap<K2, Vec<usize>>, secondary_key_mapping: HashMap<K2, Vec<usize>>,
values: Vec<Values>, values: Vec<Values>,
} }
...@@ -65,18 +61,11 @@ where ...@@ -65,18 +61,11 @@ where
self.values.push(value); self.values.push(value);
let index = self.values.len() - 1; let index = self.values.len() - 1;
self.primary_key_mapping.insert(k1, index); self.primary_key_mapping.insert(k1, index);
self.add_secondary_key_mapping(index, &k2);
None
}
}
}
fn add_secondary_key_mapping(&mut self, index: usize, secondary_key: &K2) {
match self.secondary_key_mapping.get_mut(secondary_key) {
Some(indexes) => indexes.push(index),
None => {
self.secondary_key_mapping self.secondary_key_mapping
.insert(secondary_key.clone(), vec![index]); .entry(k2)
.or_default()
.push(index);
None
} }
} }
} }
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter