-
Notifications
You must be signed in to change notification settings - Fork 13.2k
/
Copy pathprev.rs
56 lines (47 loc) · 1.7 KB
/
prev.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
use super::serialized::{SerializedDepGraph, SerializedDepNodeIndex};
use super::{DepKind, DepNode};
use rustc_data_structures::fingerprint::Fingerprint;
use rustc_data_structures::fx::FxHashMap;
#[derive(Debug)]
pub struct PreviousDepGraph<K: DepKind> {
data: SerializedDepGraph<K>,
index: FxHashMap<DepNode<K>, SerializedDepNodeIndex>,
}
impl<K: DepKind> Default for PreviousDepGraph<K> {
fn default() -> Self {
PreviousDepGraph { data: Default::default(), index: Default::default() }
}
}
impl<K: DepKind> PreviousDepGraph<K> {
pub fn new(data: SerializedDepGraph<K>) -> PreviousDepGraph<K> {
let index: FxHashMap<_, _> =
data.nodes.iter_enumerated().map(|(idx, &dep_node)| (dep_node, idx)).collect();
PreviousDepGraph { data, index }
}
#[inline]
pub fn edge_targets_from(
&self,
dep_node_index: SerializedDepNodeIndex,
) -> &[SerializedDepNodeIndex] {
self.data.edge_targets_from(dep_node_index)
}
#[inline]
pub fn index_to_node(&self, dep_node_index: SerializedDepNodeIndex) -> DepNode<K> {
self.data.nodes[dep_node_index]
}
#[inline]
pub fn node_to_index_opt(&self, dep_node: &DepNode<K>) -> Option<SerializedDepNodeIndex> {
self.index.get(dep_node).cloned()
}
#[inline]
pub fn fingerprint_of(&self, dep_node: &DepNode<K>) -> Option<Fingerprint> {
self.index.get(dep_node).map(|&node_index| self.data.fingerprints[node_index])
}
#[inline]
pub fn fingerprint_by_index(&self, dep_node_index: SerializedDepNodeIndex) -> Fingerprint {
self.data.fingerprints[dep_node_index]
}
pub fn node_count(&self) -> usize {
self.index.len()
}
}