Commit 137eb9fd authored by Tiago Peixoto's avatar Tiago Peixoto

Fix clear_vertex() and remove_edge(s, t, g) in adj_list<>

parent 44739a41
......@@ -548,6 +548,8 @@ inline Vertex add_vertex(adj_list<Vertex>& g)
template <class Vertex>
inline void clear_vertex(Vertex v, adj_list<Vertex>& g)
{
if (!g._keep_epos)
{
typename adj_list<Vertex>::edge_list_t& oes = g._out_edges[v];
for (size_t i = 0; i < oes.size(); ++i)
{
......@@ -581,6 +583,41 @@ inline void clear_vertex(Vertex v, adj_list<Vertex>& g)
}
g._n_edges -= ies.size();
ies.clear();
}
else
{
typename adj_list<Vertex>::edge_list_t& oes = g._out_edges[v];
for (size_t i = 0; i < oes.size(); ++i)
{
Vertex t = oes[i].first;
size_t idx = oes[i].second;
typename adj_list<Vertex>::edge_list_t& ies = g._in_edges[t];
const std::pair<int32_t, int32_t>& pos = g._epos[idx];
g._epos[ies.back().second].second = pos.second;
ies[pos.second] = ies.back();
ies.pop_back();
g._free_indexes.push_back(idx);
}
g._n_edges -= oes.size();
oes.clear();
typename adj_list<Vertex>::edge_list_t& ies = g._in_edges[v];
for (size_t i = 0; i < ies.size(); ++i)
{
Vertex s = ies[i].first;
size_t idx = ies[i].second;
typename adj_list<Vertex>::edge_list_t& oes = g._out_edges[s];
const std::pair<int32_t, int32_t>& pos = g._epos[idx];
g._epos[oes.back().second].first = pos.first;
oes[pos.first] = oes.back();
oes.pop_back();
g._free_indexes.push_back(idx);
}
g._n_edges -= ies.size();
ies.clear();
}
}
// O(V + E)
......@@ -689,6 +726,8 @@ template <class Vertex>
inline void remove_edge(Vertex s, Vertex t,
adj_list<Vertex>& g)
{
if (!g._keep_epos)
{
typename adj_list<Vertex>::edge_list_t& oes = g._out_edges[s];
for (size_t i = 0; i < oes.size(); ++i)
{
......@@ -706,6 +745,11 @@ inline void remove_edge(Vertex s, Vertex t,
if (s == ies[i].first)
ies.erase(ies.begin() + i);
}
}
else
{
remove_edge(edge(s, t, g).first, g);
}
}
template <class Vertex>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment