提交 dbaf300a 编写于 作者: F Felix S. Klock II 提交者: Alex Crichton

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.)
上级 7f88cfde
......@@ -70,10 +70,14 @@ pub struct Direction { repr: uint }
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 @@ pub fn next_adjacent(&self, edge: EdgeIndex, dir: Direction) -> EdgeIndex {
///////////////////////////////////////////////////////////////////////////
// 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 @@ pub fn each_adjacent_edge(&self,
// 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 {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册