Commit 1845dd07 authored by Tiago Peixoto's avatar Tiago Peixoto

Improve label_self_loops()

parent f2bdc674
......@@ -37,12 +37,13 @@ void do_label_parallel_edges(GraphInterface& gi, boost::any property,
void do_label_self_loops(GraphInterface& gi, boost::any property)
void do_label_self_loops(GraphInterface& gi, boost::any property,
bool mark_only)
GraphInterface::edge_index_map_t edge_index =
run_action<>()(gi, bind<void>(label_self_loops(), _1,
edge_index, _2),
edge_index, _2, mark_only),
......@@ -72,7 +72,7 @@ struct label_self_loops
template <class Graph, class EdgeIndexMap, class SelfMap>
void operator()(const Graph& g, EdgeIndexMap edge_index,
SelfMap self) const
SelfMap self, bool mark_only) const
typedef typename graph_traits<Graph>::edge_descriptor edge_t;
......@@ -89,7 +89,7 @@ struct label_self_loops
for (tie(e, e_end) = out_edges(v, g); e != e_end; ++e)
if (target(*e, g) == v)
put(self, *e, n++);
put(self, *e, mark_only ? 1 : n++);
put(self, *e, 0);
......@@ -303,16 +303,21 @@ def remove_parallel_edges(g):
remove_labeled_edges(g, eprop)
def label_self_loops(g, eprop=None):
def label_self_loops(g, mark_only=False, eprop=None):
"""Label edges which are self-loops, i.e, the source and target vertices are
the same. Self-loops are labeled with 1 and others with 0. If the `eprop`
parameter is given (a :class:`~graph_tool.PropertyMap`), the labelling is
stored there."""
the same. For each self-loop edge set :math:`SL`, the labelling starts from 0
to :math:`|SL|-1`. If `mark_only == True`, self-loops are labeled with 1
and others with 0. If the `eprop` parameter is given
(a :class:`~graph_tool.PropertyMap`), the labelling is stored there."""
if eprop == None:
eprop = g.new_edge_property("int32_t")
if eprop is None:
if mark_only:
eprop = g.new_edge_property("bool")
eprop = g.new_edge_property("int32_t")
label_self_loops(g._Graph__graph, _prop("e", g, eprop))
label_self_loops(g._Graph__graph, _prop("e", g, eprop),
return eprop
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