Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Tiago Peixoto
graph-tool
Commits
31373d8f
Commit
31373d8f
authored
Apr 19, 2014
by
Tiago Peixoto
Browse files
Fix Graph.clear() and Graph.clear_edges() behavior for filtered graphs
parent
eb743ada
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/graph/graph.cc
View file @
31373d8f
...
...
@@ -79,15 +79,38 @@ size_t GraphInterface::GetNumberOfEdges()
return
n
;
}
struct
clear_vertices
{
template
<
class
Graph
>
void
operator
()(
Graph
&
g
)
const
{
int
N
=
num_vertices
(
g
);
for
(
int
i
=
N
-
1
;
i
>=
0
;
--
i
)
{
auto
v
=
vertex
(
i
,
g
);
if
(
v
==
graph_traits
<
Graph
>::
null_vertex
())
continue
;
remove_vertex
(
v
,
g
);
}
}
};
void
GraphInterface
::
Clear
()
{
*
_mg
=
multigraph_t
();
run_action
<>
()(
*
this
,
std
::
bind
(
clear_vertices
(),
placeholders
::
_1
))
();
}
struct
clear_edges
{
template
<
class
Graph
>
void
operator
()(
Graph
&
g
)
const
{
for
(
auto
v
:
vertices_range
(
g
))
clear_vertex
(
v
,
g
);
}
};
void
GraphInterface
::
ClearEdges
()
{
graph_traits
<
multigraph_t
>::
vertex_iterator
v
,
v_end
;
for
(
tie
(
v
,
v_end
)
=
vertices
(
*
_mg
);
v
!=
v_end
;
++
v
)
clear_vertex
(
*
v
,
*
_mg
);
_mg
->
reindex_edges
();
run_action
<>
()(
*
this
,
std
::
bind
(
clear_edges
(),
placeholders
::
_1
))();
}
src/graph/graph_adaptor.hh
View file @
31373d8f
...
...
@@ -561,6 +561,17 @@ inline void remove_vertex
remove_vertex
(
u
,
g
.
OriginalGraph
());
}
//==============================================================================
// remove_vertex_fast(u,g)
//==============================================================================
template
<
class
Graph
>
inline
void
remove_vertex_fast
(
typename
graph_traits
<
UndirectedAdaptor
<
Graph
>
>::
vertex_descriptor
u
,
UndirectedAdaptor
<
Graph
>&
g
)
{
remove_vertex_fast
(
u
,
g
.
OriginalGraph
());
}
//==============================================================================
// add_edge(u,v,g)
//==============================================================================
...
...
src/graph/graph_util.hh
View file @
31373d8f
...
...
@@ -39,6 +39,8 @@
#include <functional>
#include <random>
#include "graph_selectors.hh"
namespace
graph_tool
{
...
...
@@ -225,7 +227,12 @@ clear_vertex(typename boost::graph_traits
<
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>>::
vertex_descriptor
v
,
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>&
g
)
{
return
clear_vertex
(
v
,
const_cast
<
Graph
&>
(
g
.
m_g
));
typedef
typename
boost
::
graph_traits
<
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>>::
edge_descriptor
e_t
;
std
::
vector
<
e_t
>
e_list
;
for
(
auto
e
:
graph_tool
::
all_edges_range
(
v
,
g
))
e_list
.
push_back
(
e
);
for
(
auto
&
e
:
e_list
)
remove_edge
(
e
,
g
);
}
//==============================================================================
...
...
@@ -270,26 +277,72 @@ void remove_edge(typename boost::graph_traits
return
remove_edge
(
e
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
//==============================================================================
//remove_vertex(v, filtered_graph<G>)
//==============================================================================
template
<
class
Graph
,
class
EdgePredicate
,
class
VertexPredicate
>
inline
void
remove_vertex
(
typename
boost
::
graph_traits
<
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>>::
vertex_descriptor
v
,
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>&
g
)
{
return
remove_vertex
(
v
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
//==============================================================================
//remove_vertex_fast(v, filtered_graph<G>)
//==============================================================================
template
<
class
Graph
,
class
EdgePredicate
,
class
VertexPredicate
>
inline
void
remove_vertex_fast
(
typename
boost
::
graph_traits
<
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>>::
vertex_descriptor
v
,
filtered_graph
<
Graph
,
EdgePredicate
,
VertexPredicate
>&
g
)
{
return
remove_vertex_fast
(
v
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
//==============================================================================
//remove_edge(e, reverse_graph<G>)
//==============================================================================
template
<
class
Graph
>
inline
void
remove_edge
(
typename
boost
::
graph_traits
<
reverse_graph
<
Graph
>>::
edge_descriptor
e
,
reverse_graph
<
Graph
>&
g
)
void
remove_edge
(
typename
boost
::
graph_traits
<
reverse_graph
<
Graph
>>::
edge_descriptor
e
,
reverse_graph
<
Graph
>&
g
)
{
return
remove_edge
(
e
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
//==============================================================================
//remove_vertex(v, reverse_graph<G>)
//==============================================================================
template
<
class
Graph
>
inline
void
remove_vertex
(
typename
boost
::
graph_traits
<
reverse_graph
<
Graph
>>::
vertex_descriptor
v
,
reverse_graph
<
Graph
>&
g
)
{
return
remove_vertex
(
v
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
//==============================================================================
//remove_vertex_fast(v, reverse_graph<G>)
//==============================================================================
template
<
class
Graph
>
inline
void
remove_vertex_fast
(
typename
boost
::
graph_traits
<
reverse_graph
<
Graph
>>::
vertex_descriptor
v
,
reverse_graph
<
Graph
>&
g
)
{
return
remove_vertex_fast
(
v
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
//==============================================================================
//clear_vertex(v, reverse_graph<G>)
//==============================================================================
template
<
class
Graph
>
inline
void
clear_vertex
(
typename
boost
::
graph_traits
<
reverse_graph
<
Graph
>>::
vertex_descriptor
v
,
reverse_graph
<
Graph
>&
g
)
void
clear_vertex
(
typename
boost
::
graph_traits
<
reverse_graph
<
Graph
>>::
vertex_descriptor
v
,
reverse_graph
<
Graph
>&
g
)
{
return
clear_vertex
(
v
,
const_cast
<
Graph
&>
(
g
.
m_g
));
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment