simplifying edge_iterator::advance

for/release
Denes Matetelki 12 years ago
parent c59e8cfeb7
commit eb638d6f6a

@ -267,40 +267,31 @@ void Graph<T>::edge_iterator::resetEdge()
if (m_vertex_it == m_vertices.end() || (*m_vertex_it).m_edges.empty()) { if (m_vertex_it == m_vertices.end() || (*m_vertex_it).m_edges.empty()) {
m_edge = 0; m_edge = 0;
return; } else {
}
m_edge = new Edge((*m_vertex_it).m_data, m_edge = new Edge((*m_vertex_it).m_data,
(*m_edge_it).m_destination, (*m_edge_it).m_destination,
(*m_edge_it).m_weight); (*m_edge_it).m_weight);
} }
}
/// @todo Rewrite it to be more simple
template <typename T> template <typename T>
void Graph<T>::edge_iterator::advance(int n) void Graph<T>::edge_iterator::advance(int n)
{ {
if (m_vertex_it == m_vertices.end()) return; while (n > 0 && m_vertex_it != m_vertices.end()) {
while (true) {
const int edgesAhead = std::distance(m_edge_it, (*m_vertex_it).m_edges.end()) - 1; const int edgesAhead = std::distance(m_edge_it, (*m_vertex_it).m_edges.end()) - 1;
if (n <= edgesAhead) { if (n <= edgesAhead) {
std::advance(m_edge_it, n); std::advance(m_edge_it, n);
return; return;
} }
if (edgesAhead > 0) if (edgesAhead > 0) n -= edgesAhead;
n -= edgesAhead;
++m_vertex_it; ++m_vertex_it;
if (m_vertex_it != m_vertices.end()) {
if (m_vertex_it == m_vertices.end())
return;
m_edge_it = (*m_vertex_it).m_edges.begin(); m_edge_it = (*m_vertex_it).m_edges.begin();
if (m_edge_it != (*m_vertex_it).m_edges.end()) if (m_edge_it != (*m_vertex_it).m_edges.end())
--n; --n;
}
if (n == 0) return;
} }
} }

Loading…
Cancel
Save