forked from denisidoro/navi
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheat.rs
59 lines (51 loc) · 1.7 KB
/
cheat.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use crate::common::hash::fnv;
use crate::finder::structures::Opts;
use crate::prelude::*;
pub type Suggestion = (String, Option<Opts>);
#[derive(Clone, Default)]
pub struct VariableMap {
variables: HashMap<u64, HashMap<String, Suggestion>>,
dependencies: HashMap<u64, Vec<u64>>,
}
impl VariableMap {
pub fn insert_dependency(&mut self, tags: &str, tags_dependency: &str) {
let k = fnv(&tags);
if let Some(v) = self.dependencies.get_mut(&k) {
v.push(fnv(&tags_dependency));
} else {
let v: Vec<u64> = vec![fnv(&tags_dependency)];
self.dependencies.insert(k, v);
}
}
pub fn insert_suggestion(&mut self, tags: &str, variable: &str, value: Suggestion) {
let k1 = fnv(&tags);
let k2 = String::from(variable);
if let Some(m) = self.variables.get_mut(&k1) {
m.insert(k2, value);
} else {
let mut m = HashMap::new();
m.insert(k2, value);
self.variables.insert(k1, m);
}
}
pub fn get_suggestion(&self, tags: &str, variable: &str) -> Option<&Suggestion> {
let k = fnv(&tags);
if let Some(vm) = self.variables.get(&k) {
let res = vm.get(variable);
if res.is_some() {
return res;
}
}
if let Some(dependency_keys) = self.dependencies.get(&k) {
for dependency_key in dependency_keys {
if let Some(vm) = self.variables.get(dependency_key) {
let res = vm.get(variable);
if res.is_some() {
return res;
}
}
}
}
None
}
}