about summary refs log tree commit diff
path: root/src/librustc_data_structures/graph
diff options
context:
space:
mode:
authorNiko Matsakis <niko@alum.mit.edu>2016-01-05 13:02:57 -0500
committerNiko Matsakis <niko@alum.mit.edu>2016-01-05 21:05:50 -0500
commitc77cd480cf2105afcbb92de4f514f1f9637912c5 (patch)
treee20124bc8fe86c9183716ac5fe0c7d47228c5efe /src/librustc_data_structures/graph
parentbadc23b6ad47c6b6d401a3ea1dc5163bdcd86cd7 (diff)
downloadrust-c77cd480cf2105afcbb92de4f514f1f9637912c5.tar.gz
rust-c77cd480cf2105afcbb92de4f514f1f9637912c5.zip
Introduce the DepGraph and DepTracking map abstractions,
along with a README explaining how they are to be used
Diffstat (limited to 'src/librustc_data_structures/graph')
-rw-r--r--src/librustc_data_structures/graph/mod.rs14
1 files changed, 11 insertions, 3 deletions
diff --git a/src/librustc_data_structures/graph/mod.rs b/src/librustc_data_structures/graph/mod.rs
index 4a3810c822b..1ea09490aed 100644
--- a/src/librustc_data_structures/graph/mod.rs
+++ b/src/librustc_data_structures/graph/mod.rs
@@ -77,16 +77,16 @@ impl<E: Debug> Debug for Edge<E> {
     }
 }
 
-#[derive(Copy, Clone, PartialEq, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
 pub struct NodeIndex(pub usize);
 
-#[derive(Copy, Clone, PartialEq, Debug)]
+#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
 pub struct EdgeIndex(pub usize);
 
 pub const INVALID_EDGE_INDEX: EdgeIndex = EdgeIndex(usize::MAX);
 
 // Use a private field here to guarantee no more instances are created:
-#[derive(Copy, Clone, Debug)]
+#[derive(Copy, Clone, Debug, PartialEq)]
 pub struct Direction { repr: usize }
 
 pub const OUTGOING: Direction = Direction { repr: 0 };
@@ -410,4 +410,12 @@ impl<E> Edge<E> {
     pub fn target(&self) -> NodeIndex {
         self.target
     }
+
+    pub fn source_or_target(&self, direction: Direction) -> NodeIndex {
+        if direction == OUTGOING {
+            self.target
+        } else {
+            self.source
+        }
+    }
 }