[Lemon-commits] Peter Kovacs: Much better implementation for nod...
Lemon HG
hg at lemon.cs.elte.hu
Wed Sep 30 08:52:47 CEST 2009
details: http://lemon.cs.elte.hu/hg/lemon/rev/456fa5bc3256
changeset: 789:456fa5bc3256
user: Peter Kovacs <kpeter [at] inf.elte.hu>
date: Sun Aug 23 11:13:21 2009 +0200
description:
Much better implementation for node splitting (#311) in ListDigraph.
This solution is the same as the one that is used in SmartDigraph.
It is much faster and does not invalidate any iterator like the
former implementation.
diffstat:
lemon/list_graph.h | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diffs (52 lines):
diff --git a/lemon/list_graph.h b/lemon/list_graph.h
--- a/lemon/list_graph.h
+++ b/lemon/list_graph.h
@@ -32,6 +32,8 @@
namespace lemon {
+ class ListDigraph;
+
class ListDigraphBase {
protected:
@@ -62,6 +64,7 @@
class Node {
friend class ListDigraphBase;
+ friend class ListDigraph;
protected:
int id;
@@ -77,6 +80,7 @@
class Arc {
friend class ListDigraphBase;
+ friend class ListDigraph;
protected:
int id;
@@ -467,18 +471,16 @@
///is also added.
///\return The newly created node.
///
- ///\note \c ArcIt and \c OutArcIt iterators referencing the outgoing
- ///arcs of node \c n are invalidated. Other iterators remain valid.
+ ///\note All iterators remain valid.
///
///\warning This functionality cannot be used together with the
///Snapshot feature.
Node split(Node n, bool connect = true) {
Node b = addNode();
- for(OutArcIt e(*this,n);e!=INVALID;) {
- OutArcIt f=e;
- ++f;
- changeSource(e,b);
- e=f;
+ nodes[b.id].first_out=nodes[n.id].first_out;
+ nodes[n.id].first_out=-1;
+ for(int i=nodes[b.id].first_out; i!=-1; i=arcs[i].next_out) {
+ arcs[i].source=b.id;
}
if (connect) addArc(n,b);
return b;
More information about the Lemon-commits
mailing list