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.)
This commit is contained in:
Felix S. Klock II 2014-05-06 09:34:29 +02:00 committed by Alex Crichton
parent 7f88cfde18
commit dbaf300a91

View File

@ -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<N,E> Graph<N,E> {
@ -201,39 +205,39 @@ impl<N,E> Graph<N,E> {
///////////////////////////////////////////////////////////////////////////
// Iterating over nodes, edges
pub fn each_node(&self, f: |NodeIndex, &Node<N>| -> bool) -> bool {
pub fn each_node<'a>(&'a self, f: |NodeIndex, &'a Node<N>| -> 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<E>| -> bool) -> bool {
pub fn each_edge<'a>(&'a self, f: |EdgeIndex, &'a Edge<E>| -> 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<E>| -> bool)
-> bool {
pub fn each_outgoing_edge<'a>(&'a self,
source: NodeIndex,
f: |EdgeIndex, &'a Edge<E>| -> 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<E>| -> bool)
-> bool {
pub fn each_incoming_edge<'a>(&'a self,
target: NodeIndex,
f: |EdgeIndex, &'a Edge<E>| -> 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<E>| -> bool)
-> bool {
pub fn each_adjacent_edge<'a>(&'a self,
node: NodeIndex,
dir: Direction,
f: |EdgeIndex, &'a Edge<E>| -> bool)
-> bool {
//! Iterates over all edges adjacent to the node `node`
//! in the direction `dir` (either `Outgoing` or `Incoming)
@ -257,11 +261,11 @@ impl<N,E> Graph<N,E> {
// 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<E>|
-> bool) {
pub fn iterate_until_fixed_point<'a>(&'a self,
op: |iter_index: uint,
edge_index: EdgeIndex,
edge: &'a Edge<E>|
-> bool) {
let mut iteration = 0;
let mut changed = true;
while changed {