Skip to content

Commit dbaf300

Browse files
pnkfelixalexcrichton
authored andcommitted
rustc::middle::graph API revisions.
Refine lifetimes in signature for graph node/edge iteration methods. Added `pub` `node_id` and `edge_id` methods that correspond to NodeIndex and EdgeIndex `get` methods (note that the inner index is already `pub` in the struct definitions). (I decided that `get()`, used internally, just looks too generic and that client code is clearer with more explicit method names.)
1 parent 7f88cfd commit dbaf300

File tree

1 file changed

+24
-20
lines changed

1 file changed

+24
-20
lines changed

src/librustc/middle/graph.rs

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,14 @@ pub static Incoming: Direction = Direction { repr: 1 };
7070

7171
impl NodeIndex {
7272
fn get(&self) -> uint { let NodeIndex(v) = *self; v }
73+
/// Returns unique id (unique with respect to the graph holding associated node).
74+
pub fn node_id(&self) -> uint { self.get() }
7375
}
7476

7577
impl EdgeIndex {
7678
fn get(&self) -> uint { let EdgeIndex(v) = *self; v }
79+
/// Returns unique id (unique with respect to the graph holding associated edge).
80+
pub fn edge_id(&self) -> uint { self.get() }
7781
}
7882

7983
impl<N,E> Graph<N,E> {
@@ -201,39 +205,39 @@ impl<N,E> Graph<N,E> {
201205
///////////////////////////////////////////////////////////////////////////
202206
// Iterating over nodes, edges
203207

204-
pub fn each_node(&self, f: |NodeIndex, &Node<N>| -> bool) -> bool {
208+
pub fn each_node<'a>(&'a self, f: |NodeIndex, &'a Node<N>| -> bool) -> bool {
205209
//! Iterates over all edges defined in the graph.
206210
self.nodes.iter().enumerate().advance(|(i, node)| f(NodeIndex(i), node))
207211
}
208212

209-
pub fn each_edge(&self, f: |EdgeIndex, &Edge<E>| -> bool) -> bool {
213+
pub fn each_edge<'a>(&'a self, f: |EdgeIndex, &'a Edge<E>| -> bool) -> bool {
210214
//! Iterates over all edges defined in the graph
211215
self.edges.iter().enumerate().advance(|(i, edge)| f(EdgeIndex(i), edge))
212216
}
213217

214-
pub fn each_outgoing_edge(&self,
215-
source: NodeIndex,
216-
f: |EdgeIndex, &Edge<E>| -> bool)
217-
-> bool {
218+
pub fn each_outgoing_edge<'a>(&'a self,
219+
source: NodeIndex,
220+
f: |EdgeIndex, &'a Edge<E>| -> bool)
221+
-> bool {
218222
//! Iterates over all outgoing edges from the node `from`
219223
220224
self.each_adjacent_edge(source, Outgoing, f)
221225
}
222226

223-
pub fn each_incoming_edge(&self,
224-
target: NodeIndex,
225-
f: |EdgeIndex, &Edge<E>| -> bool)
226-
-> bool {
227+
pub fn each_incoming_edge<'a>(&'a self,
228+
target: NodeIndex,
229+
f: |EdgeIndex, &'a Edge<E>| -> bool)
230+
-> bool {
227231
//! Iterates over all incoming edges to the node `target`
228232
229233
self.each_adjacent_edge(target, Incoming, f)
230234
}
231235

232-
pub fn each_adjacent_edge(&self,
233-
node: NodeIndex,
234-
dir: Direction,
235-
f: |EdgeIndex, &Edge<E>| -> bool)
236-
-> bool {
236+
pub fn each_adjacent_edge<'a>(&'a self,
237+
node: NodeIndex,
238+
dir: Direction,
239+
f: |EdgeIndex, &'a Edge<E>| -> bool)
240+
-> bool {
237241
//! Iterates over all edges adjacent to the node `node`
238242
//! in the direction `dir` (either `Outgoing` or `Incoming)
239243
@@ -257,11 +261,11 @@ impl<N,E> Graph<N,E> {
257261
// variables or other bitsets. This method facilitates such a
258262
// computation.
259263

260-
pub fn iterate_until_fixed_point(&self,
261-
op: |iter_index: uint,
262-
edge_index: EdgeIndex,
263-
edge: &Edge<E>|
264-
-> bool) {
264+
pub fn iterate_until_fixed_point<'a>(&'a self,
265+
op: |iter_index: uint,
266+
edge_index: EdgeIndex,
267+
edge: &'a Edge<E>|
268+
-> bool) {
265269
let mut iteration = 0;
266270
let mut changed = true;
267271
while changed {

0 commit comments

Comments
 (0)