MCPcopy Create free account
hub / github.com/BirolLab/abyss / breadthFirstSearchImpl

Function breadthFirstSearchImpl

Graph/BreadthFirstSearch.h:96–173  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

94 */
95template <class Graph, class VertexSet, class ColorMap, class Visitor>
96static inline void breadthFirstSearchImpl(
97 const VertexSet& startVertices, const Graph& g, bool undirected,
98 ColorMap& colorMap, Visitor& visitor)
99{
100 typedef typename boost::graph_traits<Graph>::vertex_descriptor V;
101 typedef typename boost::graph_traits<Graph>::edge_descriptor E;
102 typedef typename boost::graph_traits<Graph>::in_edge_iterator IEIt;
103 typedef typename boost::graph_traits<Graph>::out_edge_iterator OEIt;
104
105 typedef typename VertexSet::const_iterator VertexListConstIt;
106
107 typedef typename property_traits<ColorMap>::value_type ColorValue;
108 typedef color_traits<ColorValue> Color;
109
110 /* breadth-first search queue */
111 boost::queue<V> queue;
112
113 BFSVisitorResult result;
114 IEIt iei, iei_end;
115 OEIt oei, oei_end;
116
117 /* push start vertices onto search queue */
118
119 for (VertexListConstIt it = startVertices.begin(); it != startVertices.end(); ++it) {
120 ColorValue color = get(colorMap, *it);
121 if (color == Color::white()) {
122 result = visitor.discover_vertex(*it, g);
123 if (result == BFS_SKIP_ELEMENT)
124 continue;
125 else if (result == BFS_ABORT_SEARCH)
126 return;
127 put(colorMap, *it, Color::gray());
128 }
129 /*
130 * note: vertex may already be black if user is reusing colorMap across
131 * multiple searches
132 */
133 if (color != Color::black()) {
134 queue.push(*it);
135 }
136 }
137
138 /* do breadth first search */
139
140 while (!queue.empty()) {
141
142 V u = queue.top();
143 queue.pop();
144 result = visitor.examine_vertex(u, g);
145 if (result == BFS_SKIP_ELEMENT)
146 continue;
147 else if (result == BFS_ABORT_SEARCH)
148 return;
149
150 for (boost::tie(oei, oei_end) = out_edges(u, g); oei != oei_end; ++oei) {
151 const E& e = *oei;
152 result = bfsVisitEdge(e, true, g, queue, colorMap, visitor);
153 if (result == BFS_ABORT_SEARCH)

Callers 2

breadthFirstSearchFunction · 0.85
breadthFirstSearchMultiFunction · 0.85

Calls 14

bfsVisitEdgeFunction · 0.85
pushMethod · 0.80
popMethod · 0.80
getFunction · 0.70
putFunction · 0.70
out_edgesFunction · 0.70
in_edgesFunction · 0.70
beginMethod · 0.45
endMethod · 0.45
discover_vertexMethod · 0.45
emptyMethod · 0.45
examine_vertexMethod · 0.45

Tested by

no test coverage detected