# HG changeset patch
# User alpar
# Date 1100888245 0
# Node ID 072bddac076e4de531ecec3bfa602ab4fac5d1d7
# Parent 8cb323dbae93f92c71bbbdd3347ec8335e497700
reverseEdge() and contract() member-functions added.
diff -r 8cb323dbae93 -r 072bddac076e src/lemon/list_graph.h
--- a/src/lemon/list_graph.h Fri Nov 19 17:22:29 2004 +0000
+++ b/src/lemon/list_graph.h Fri Nov 19 18:17:25 2004 +0000
@@ -313,8 +313,9 @@
///This is a simple and fast erasable graph implementation.
///
- ///It conforms to the
- ///\ref concept::ErasableGraph "ErasableGraph" concept.
+ ///It addition that it conforms to the
+ ///\ref concept::ErasableGraph "ErasableGraph" concept,
+ ///it also provides several additional useful extra functionalities.
///\sa concept::ErasableGraph.
class ListGraph : public ErasableListGraphBase
@@ -324,17 +325,67 @@
/// Moves the target of \c e to \c n
///
+ ///\note The Edge's and OutEdge's
+ ///referencing the moved edge remain
+ ///valid. However InEdge's are invalidated.
void moveTarget(Edge e, Node n) { _moveTarget(e,n); }
/// Moves the source of \c e to \c n
/// Moves the source of \c e to \c n
///
+ ///\note The Edge's and InEdge's
+ ///referencing the moved edge remain
+ ///valid. However OutEdge's are invalidated.
void moveSource(Edge e, Node n) { _moveSource(e,n); }
+ /// Invert the direction of an edge.
+
+ ///\note The Edge's
+ ///referencing the moved edge remain
+ ///valid. However OutEdge's and InEdge's are invalidated.
+ void reverseEdge(Edge e) {
+ Node t=target(e);
+ _moveTarget(e,source(e));
+ _moveSource(e,t);
+ }
+
+ ///Using this it possible to avoid the superfluous memory allocation.
+
///Using this it possible to avoid the superfluous memory allocation.
///\todo more docs...
void reserveEdge(int n) { edges.reserve(n); };
-
+
+ ///Contract two nodes.
+
+ ///This function contracts two nodes.
+ ///
+ ///Node \p b will be removed but instead of deleting
+ ///its neighboring edges, they will be joined to \p a.
+ ///The last parameter \p r controls whether to remove loops. \c true
+ ///means that loops will be removed.
+ ///
+ ///\note The Edges
+ ///referencing the moved edge remain
+ ///valid. However InEdge's and OutEdge's
+ ///may be invalidated.
+ void contract(Node a,Node b,bool r=true)
+ {
+ for(OutEdgeIt e(*this,b);e!=INVALID;) {
+ OutEdgeIt f=e;
+ ++f;
+ if(r && target(e)==a) erase(e);
+ else moveSource(e,b);
+ e=f;
+ }
+ for(InEdgeIt e(*this,b);e!=INVALID;) {
+ InEdgeIt f=e;
+ ++f;
+ if(r && source(e)==a) erase(e);
+ else moveTarget(e,b);
+ e=f;
+ }
+ erase(b);
+ }
};
/// @}