@@ -10,17 +10,43 @@ use crate::util::interning::{InternedString, INTERNED_DEFAULT};
10
10
use crate :: util:: CargoResult ;
11
11
use std:: collections:: { HashMap , HashSet } ;
12
12
13
- #[ derive( Debug , Copy , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
13
+ #[ derive( Debug , Copy , Clone ) ]
14
14
pub struct NodeId {
15
15
index : usize ,
16
16
}
17
17
18
18
impl NodeId {
19
- fn with_index ( index : usize ) -> Self {
19
+ fn new ( index : usize ) -> Self {
20
20
Self { index }
21
21
}
22
22
}
23
23
24
+ impl PartialEq for NodeId {
25
+ fn eq ( & self , other : & Self ) -> bool {
26
+ self . index == other. index
27
+ }
28
+ }
29
+
30
+ impl Eq for NodeId { }
31
+
32
+ impl PartialOrd for NodeId {
33
+ fn partial_cmp ( & self , other : & Self ) -> Option < std:: cmp:: Ordering > {
34
+ Some ( self . cmp ( other) )
35
+ }
36
+ }
37
+
38
+ impl Ord for NodeId {
39
+ fn cmp ( & self , other : & Self ) -> std:: cmp:: Ordering {
40
+ self . index . cmp ( & other. index )
41
+ }
42
+ }
43
+
44
+ impl std:: hash:: Hash for NodeId {
45
+ fn hash < H : std:: hash:: Hasher > ( & self , state : & mut H ) {
46
+ self . index . hash ( state)
47
+ }
48
+ }
49
+
24
50
#[ derive( Debug , Clone , Eq , PartialEq , Hash , Ord , PartialOrd ) ]
25
51
pub enum Node {
26
52
Package {
@@ -134,7 +160,7 @@ impl<'a> Graph<'a> {
134
160
135
161
/// Adds a new node to the graph, returning its new index.
136
162
fn add_node ( & mut self , node : Node ) -> NodeId {
137
- let from_index = NodeId :: with_index ( self . nodes . len ( ) ) ;
163
+ let from_index = NodeId :: new ( self . nodes . len ( ) ) ;
138
164
self . nodes . push ( node) ;
139
165
self . edges . push ( Edges :: new ( ) ) ;
140
166
self . index . insert ( self . node ( from_index) . clone ( ) , from_index) ;
@@ -178,7 +204,7 @@ impl<'a> Graph<'a> {
178
204
Node :: Package { package_id, .. } => package_ids. contains ( package_id) ,
179
205
_ => false ,
180
206
} )
181
- . map ( |( i, node) | ( node, NodeId :: with_index ( i) ) )
207
+ . map ( |( i, node) | ( node, NodeId :: new ( i) ) )
182
208
. collect ( ) ;
183
209
// Sort for consistent output (the same command should always return
184
210
// the same output). "unstable" since nodes should always be unique.
@@ -252,7 +278,7 @@ impl<'a> Graph<'a> {
252
278
for edge in node_edges. all ( ) {
253
279
let new_edge = Edge {
254
280
kind : edge. kind ( ) ,
255
- node : NodeId :: with_index ( from_idx) ,
281
+ node : NodeId :: new ( from_idx) ,
256
282
} ;
257
283
new_edges[ edge. node ( ) . index ] . add_edge ( new_edge) ;
258
284
}
@@ -273,7 +299,7 @@ impl<'a> Graph<'a> {
273
299
packages
274
300
. entry ( package_id. name ( ) )
275
301
. or_insert_with ( Vec :: new)
276
- . push ( ( node, NodeId :: with_index ( i) ) ) ;
302
+ . push ( ( node, NodeId :: new ( i) ) ) ;
277
303
}
278
304
}
279
305
@@ -645,7 +671,7 @@ fn add_internal_features(graph: &mut Graph<'_>, resolve: &Resolve) {
645
671
Node :: Package { .. } => None ,
646
672
Node :: Feature { node_index, name } => {
647
673
let package_id = graph. package_id_for_index ( * node_index) ;
648
- Some ( ( package_id, * node_index, NodeId :: with_index ( i) , * name) )
674
+ Some ( ( package_id, * node_index, NodeId :: new ( i) , * name) )
649
675
}
650
676
} )
651
677
. collect ( ) ;
0 commit comments