diff --git a/src/librustc/middle/graph.rs b/src/librustc/middle/graph.rs index 2705f9bf9bf4..5773d0bafa1d 100644 --- a/src/librustc/middle/graph.rs +++ b/src/librustc/middle/graph.rs @@ -70,10 +70,14 @@ pub static Incoming: Direction = Direction { repr: 1 }; impl NodeIndex { fn get(&self) -> uint { let NodeIndex(v) = *self; v } + /// Returns unique id (unique with respect to the graph holding associated node). + pub fn node_id(&self) -> uint { self.get() } } impl EdgeIndex { fn get(&self) -> uint { let EdgeIndex(v) = *self; v } + /// Returns unique id (unique with respect to the graph holding associated edge). + pub fn edge_id(&self) -> uint { self.get() } } impl Graph { @@ -201,39 +205,39 @@ impl Graph { /////////////////////////////////////////////////////////////////////////// // Iterating over nodes, edges - pub fn each_node(&self, f: |NodeIndex, &Node| -> bool) -> bool { + pub fn each_node<'a>(&'a self, f: |NodeIndex, &'a Node| -> bool) -> bool { //! Iterates over all edges defined in the graph. self.nodes.iter().enumerate().advance(|(i, node)| f(NodeIndex(i), node)) } - pub fn each_edge(&self, f: |EdgeIndex, &Edge| -> bool) -> bool { + pub fn each_edge<'a>(&'a self, f: |EdgeIndex, &'a Edge| -> bool) -> bool { //! Iterates over all edges defined in the graph self.edges.iter().enumerate().advance(|(i, edge)| f(EdgeIndex(i), edge)) } - pub fn each_outgoing_edge(&self, - source: NodeIndex, - f: |EdgeIndex, &Edge| -> bool) - -> bool { + pub fn each_outgoing_edge<'a>(&'a self, + source: NodeIndex, + f: |EdgeIndex, &'a Edge| -> bool) + -> bool { //! Iterates over all outgoing edges from the node `from` self.each_adjacent_edge(source, Outgoing, f) } - pub fn each_incoming_edge(&self, - target: NodeIndex, - f: |EdgeIndex, &Edge| -> bool) - -> bool { + pub fn each_incoming_edge<'a>(&'a self, + target: NodeIndex, + f: |EdgeIndex, &'a Edge| -> bool) + -> bool { //! Iterates over all incoming edges to the node `target` self.each_adjacent_edge(target, Incoming, f) } - pub fn each_adjacent_edge(&self, - node: NodeIndex, - dir: Direction, - f: |EdgeIndex, &Edge| -> bool) - -> bool { + pub fn each_adjacent_edge<'a>(&'a self, + node: NodeIndex, + dir: Direction, + f: |EdgeIndex, &'a Edge| -> bool) + -> bool { //! Iterates over all edges adjacent to the node `node` //! in the direction `dir` (either `Outgoing` or `Incoming) @@ -257,11 +261,11 @@ impl Graph { // variables or other bitsets. This method facilitates such a // computation. - pub fn iterate_until_fixed_point(&self, - op: |iter_index: uint, - edge_index: EdgeIndex, - edge: &Edge| - -> bool) { + pub fn iterate_until_fixed_point<'a>(&'a self, + op: |iter_index: uint, + edge_index: EdgeIndex, + edge: &'a Edge| + -> bool) { let mut iteration = 0; let mut changed = true; while changed {