2 * src/hugo/list_graph.h - Part of HUGOlib, a generic C++ optimization library
4 * Copyright (C) 2004 Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
5 * (Egervary Combinatorial Optimization Research Group, EGRES).
7 * Permission to use, modify and distribute this software is granted
8 * provided that this copyright notice appears in all copies. For
9 * precise terms see the accompanying LICENSE file.
11 * This software is provided "AS IS" with no warranty of any kind,
12 * express or implied, and with no claim as to its suitability for any
17 #ifndef HUGO_LIST_GRAPH_H
18 #define HUGO_LIST_GRAPH_H
22 ///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
27 #include <hugo/invalid.h>
29 #include <hugo/map_registry.h>
30 #include <hugo/array_map.h>
32 #include <hugo/sym_map.h>
34 #include <hugo/map_defines.h>
39 /// \addtogroup graphs
42 ///A list graph class.
44 ///This is a simple and fast erasable graph implementation.
47 ///\ref skeleton::ErasableGraph "ErasableGraph" concept.
48 ///\sa skeleton::ErasableGraph.
51 //Nodes are double linked.
52 //The free nodes are only single linked using the "next" field.
55 int first_in,first_out;
58 //Edges are double linked.
59 //The free edges are only single linked using the "next_in" field.
63 int prev_in, prev_out;
64 int next_in, next_out;
67 std::vector<NodeT> nodes;
72 std::vector<EdgeT> edges;
78 typedef ListGraph Graph;
91 // Create map registries.
92 CREATE_MAP_REGISTRIES;
93 // Create node and edge maps.
94 CREATE_MAPS(ArrayMap);
99 : nodes(), first_node(-1),
100 first_free_node(-1), edges(), first_free_edge(-1) {}
102 ListGraph(const ListGraph &_g)
103 : nodes(_g.nodes), first_node(_g.first_node),
104 first_free_node(_g.first_free_node), edges(_g.edges),
105 first_free_edge(_g.first_free_edge) {}
108 int nodeNum() const { return nodes.size(); }
110 int edgeNum() const { return edges.size(); }
112 ///Set the expected maximum number of edges.
114 ///With this function, it is possible to set the expected number of edges.
115 ///The use of this fasten the building of the graph and makes
116 ///it possible to avoid the superfluous memory allocation.
117 void reserveEdge(int n) { edges.reserve(n); };
123 int maxNodeId() const { return nodes.size()-1; }
128 int maxEdgeId() const { return edges.size()-1; }
130 Node tail(Edge e) const { return edges[e.n].tail; }
131 Node head(Edge e) const { return edges[e.n].head; }
133 NodeIt& first(NodeIt& v) const {
134 v=NodeIt(*this); return v; }
135 EdgeIt& first(EdgeIt& e) const {
136 e=EdgeIt(*this); return e; }
137 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
138 e=OutEdgeIt(*this,v); return e; }
139 InEdgeIt& first(InEdgeIt& e, const Node v) const {
140 e=InEdgeIt(*this,v); return e; }
144 /// The ID of a valid Node is a nonnegative integer not greater than
145 /// \ref maxNodeId(). The range of the ID's is not surely continuous
146 /// and the greatest node ID can be actually less then \ref maxNodeId().
148 /// The ID of the \ref INVALID node is -1.
149 ///\return The ID of the node \c v.
150 static int id(Node v) { return v.n; }
153 /// The ID of a valid Edge is a nonnegative integer not greater than
154 /// \ref maxEdgeId(). The range of the ID's is not surely continuous
155 /// and the greatest edge ID can be actually less then \ref maxEdgeId().
157 /// The ID of the \ref INVALID edge is -1.
158 ///\return The ID of the edge \c e.
159 static int id(Edge e) { return e.n; }
161 /// Adds a new node to the graph.
163 /// \warning It adds the new node to the front of the list.
164 /// (i.e. the lastly added node becomes the first.)
168 if(first_free_node==-1)
171 nodes.push_back(NodeT());
175 first_free_node = nodes[n].next;
178 nodes[n].next = first_node;
179 if(first_node != -1) nodes[first_node].prev = n;
183 nodes[n].first_in = nodes[n].first_out = -1;
187 //Update dynamic maps
193 Edge addEdge(Node u, Node v) {
196 if(first_free_edge==-1)
199 edges.push_back(EdgeT());
203 first_free_edge = edges[n].next_in;
206 edges[n].tail = u.n; edges[n].head = v.n;
208 edges[n].next_out = nodes[u.n].first_out;
209 if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n;
210 edges[n].next_in = nodes[v.n].first_in;
211 if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n;
212 edges[n].prev_in = edges[n].prev_out = -1;
214 nodes[u.n].first_out = nodes[v.n].first_in = n;
218 //Update dynamic maps
224 /// Finds an edge between two nodes.
226 /// Finds an edge from node \c u to node \c v.
228 /// If \c prev is \ref INVALID (this is the default value), then
229 /// It finds the first edge from \c u to \c v. Otherwise it looks for
230 /// the next edge from \c u to \c v after \c prev.
231 /// \return The found edge or INVALID if there is no such an edge.
232 Edge findEdge(Node u,Node v, Edge prev = INVALID)
234 int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
235 while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
241 void eraseEdge(int n) {
243 if(edges[n].next_in!=-1)
244 edges[edges[n].next_in].prev_in = edges[n].prev_in;
245 if(edges[n].prev_in!=-1)
246 edges[edges[n].prev_in].next_in = edges[n].next_in;
247 else nodes[edges[n].head].first_in = edges[n].next_in;
249 if(edges[n].next_out!=-1)
250 edges[edges[n].next_out].prev_out = edges[n].prev_out;
251 if(edges[n].prev_out!=-1)
252 edges[edges[n].prev_out].next_out = edges[n].next_out;
253 else nodes[edges[n].tail].first_out = edges[n].next_out;
255 edges[n].next_in = first_free_edge;
258 //Update dynamic maps
266 void erase(Node nn) {
270 while((m=nodes[n].first_in)!=-1) eraseEdge(m);
271 while((m=nodes[n].first_out)!=-1) eraseEdge(m);
273 if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
274 if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
275 else first_node = nodes[n].next;
277 nodes[n].next = first_free_node;
280 //Update dynamic maps
285 void erase(Edge e) { eraseEdge(e.n); }
292 first_node=first_free_node=first_free_edge=-1;
296 friend class ListGraph;
297 template <typename T> friend class NodeMap;
300 friend class OutEdgeIt;
301 friend class InEdgeIt;
302 friend class SymEdge;
306 friend int ListGraph::id(Node v);
310 Node (Invalid) { n=-1; }
311 bool operator==(const Node i) const {return n==i.n;}
312 bool operator!=(const Node i) const {return n!=i.n;}
313 bool operator<(const Node i) const {return n<i.n;}
315 // operator bool() { return n!=-1; }
318 class NodeIt : public Node {
320 friend class ListGraph;
322 NodeIt() : Node() { }
323 NodeIt(Invalid i) : Node(i) { }
324 NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
325 NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { }
326 NodeIt &operator++() {
331 // operator bool() { return Node::operator bool(); }
335 friend class ListGraph;
336 template <typename T> friend class EdgeMap;
338 friend class SymListGraph;
344 friend int ListGraph::id(Edge e);
347 /// An Edge with id \c n.
349 /// \bug It should be
350 /// obtained by a member function of the Graph.
354 Edge (Invalid) { n=-1; }
355 bool operator==(const Edge i) const {return n==i.n;}
356 bool operator!=(const Edge i) const {return n!=i.n;}
357 bool operator<(const Edge i) const {return n<i.n;}
359 // operator bool() { return n!=-1; }
362 class EdgeIt : public Edge {
364 friend class ListGraph;
366 EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
369 m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
370 n = (m==-1)?-1:_G.nodes[m].first_in;
372 EdgeIt (Invalid i) : Edge(i) { }
373 EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
374 EdgeIt() : Edge() { }
375 EdgeIt &operator++() {
376 if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
379 for(nn=G->nodes[G->edges[n].head].next;
380 nn!=-1 && G->nodes[nn].first_in == -1;
381 nn = G->nodes[nn].next) ;
382 n = (nn==-1)?-1:G->nodes[nn].first_in;
387 // operator bool() { return Edge::operator bool(); }
390 class OutEdgeIt : public Edge {
392 friend class ListGraph;
394 OutEdgeIt() : Edge() { }
395 OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
396 OutEdgeIt (Invalid i) : Edge(i) { }
398 OutEdgeIt(const ListGraph& _G,const Node v)
399 : Edge(_G.nodes[v.n].first_out), G(&_G) {}
400 OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
402 // operator bool() { return Edge::operator bool(); }
405 class InEdgeIt : public Edge {
407 friend class ListGraph;
409 InEdgeIt() : Edge() { }
410 InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
411 InEdgeIt (Invalid i) : Edge(i) { }
412 InEdgeIt(const ListGraph& _G,Node v)
413 : Edge(_G.nodes[v.n].first_in), G(&_G) { }
414 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
416 // operator bool() { return Edge::operator bool(); }
420 ///Graph for bidirectional edges.
422 ///The purpose of this graph structure is to handle graphs
423 ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
424 ///of oppositely directed edges.
425 ///There is a new edge map type called
426 ///\ref SymListGraph::SymEdgeMap "SymEdgeMap"
427 ///that complements this
429 ///storing shared values for the edge pairs. The usual
430 ///\ref Graph::EdgeMap "EdgeMap"
434 ///The oppositely directed edge can also be obtained easily
435 ///using \ref opposite.
437 ///Here erase(Edge) deletes a pair of edges.
439 ///\todo this date structure need some reconsiderations. Maybe it
440 ///should be implemented independently from ListGraph.
442 class SymListGraph : public ListGraph
446 typedef SymListGraph Graph;
448 // Create symmetric map registry.
449 CREATE_SYM_EDGE_MAP_REGISTRY;
450 // Create symmetric edge map.
451 CREATE_SYM_EDGE_MAP(ArrayMap);
453 SymListGraph() : ListGraph() { }
454 SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
455 ///Adds a pair of oppositely directed edges to the graph.
456 Edge addEdge(Node u, Node v)
458 Edge e = ListGraph::addEdge(u,v);
459 Edge f = ListGraph::addEdge(v,u);
460 sym_edge_maps.add(e);
461 sym_edge_maps.add(f);
466 void erase(Node n) { ListGraph::erase(n);}
467 ///The oppositely directed edge.
469 ///Returns the oppositely directed
470 ///pair of the edge \c e.
471 static Edge opposite(Edge e)
474 f.n = e.n - 2*(e.n%2) + 1;
478 ///Removes a pair of oppositely directed edges to the graph.
480 Edge f = opposite(e);
481 sym_edge_maps.erase(e);
482 sym_edge_maps.erase(f);
489 ///A graph class containing only nodes.
491 ///This class implements a graph structure without edges.
492 ///The most useful application of this class is to be the node set of an
493 ///\ref EdgeSet class.
496 ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept
497 ///with the exception that you cannot
498 ///add (or delete) edges. The usual edge iterators are exists, but they are
499 ///always \ref INVALID.
500 ///\sa skeleton::ExtendableGraph
504 //Nodes are double linked.
505 //The free nodes are only single linked using the "next" field.
508 int first_in,first_out;
513 std::vector<NodeT> nodes;
516 //The first free node
521 typedef NodeSet Graph;
533 // Create node map registry.
534 CREATE_NODE_MAP_REGISTRY;
536 CREATE_NODE_MAP(ArrayMap);
538 /// Creating empty map structure for edges.
539 template <typename Value>
542 EdgeMap(const Graph&) {}
543 EdgeMap(const Graph&, const Value&) {}
545 EdgeMap(const EdgeMap&) {}
546 template <typename CMap> EdgeMap(const CMap&) {}
548 EdgeMap& operator=(const EdgeMap&) {}
549 template <typename CMap> EdgeMap& operator=(const CMap&) {}
551 class ConstIterator {
553 bool operator==(const ConstIterator&) {return true;}
554 bool operator!=(const ConstIterator&) {return false;}
557 typedef ConstIterator Iterator;
559 Iterator begin() { return Iterator();}
560 Iterator end() { return Iterator();}
562 ConstIterator begin() const { return ConstIterator();}
563 ConstIterator end() const { return ConstIterator();}
569 ///Default constructor
571 : nodes(), first_node(-1), first_free_node(-1) {}
573 NodeSet(const NodeSet &_g)
574 : nodes(_g.nodes), first_node(_g.first_node),
575 first_free_node(_g.first_free_node) {}
578 int nodeNum() const { return nodes.size(); }
580 int edgeNum() const { return 0; }
586 int maxNodeId() const { return nodes.size()-1; }
591 int maxEdgeId() const { return 0; }
593 Node tail(Edge e) const { return INVALID; }
594 Node head(Edge e) const { return INVALID; }
596 NodeIt& first(NodeIt& v) const {
597 v=NodeIt(*this); return v; }
598 EdgeIt& first(EdgeIt& e) const {
599 e=EdgeIt(*this); return e; }
600 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
601 e=OutEdgeIt(*this,v); return e; }
602 InEdgeIt& first(InEdgeIt& e, const Node v) const {
603 e=InEdgeIt(*this,v); return e; }
607 /// The ID of a valid Node is a nonnegative integer not greater than
608 /// \ref maxNodeId(). The range of the ID's is not surely continuous
609 /// and the greatest node ID can be actually less then \ref maxNodeId().
611 /// The ID of the \ref INVALID node is -1.
612 ///\return The ID of the node \c v.
613 static int id(Node v) { return v.n; }
616 /// The ID of a valid Edge is a nonnegative integer not greater than
617 /// \ref maxEdgeId(). The range of the ID's is not surely continuous
618 /// and the greatest edge ID can be actually less then \ref maxEdgeId().
620 /// The ID of the \ref INVALID edge is -1.
621 ///\return The ID of the edge \c e.
622 static int id(Edge e) { return -1; }
624 /// Adds a new node to the graph.
626 /// \warning It adds the new node to the front of the list.
627 /// (i.e. the lastly added node becomes the first.)
631 if(first_free_node==-1)
634 nodes.push_back(NodeT());
638 first_free_node = nodes[n].next;
641 nodes[n].next = first_node;
642 if(first_node != -1) nodes[first_node].prev = n;
646 nodes[n].first_in = nodes[n].first_out = -1;
650 //Update dynamic maps
656 void erase(Node nn) {
659 if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
660 if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
661 else first_node = nodes[n].next;
663 nodes[n].next = first_free_node;
666 //Update dynamic maps
671 Edge findEdge(Node u,Node v, Edge prev = INVALID)
679 first_node = first_free_node = -1;
683 friend class NodeSet;
684 template <typename T> friend class NodeMap;
687 friend class OutEdgeIt;
688 friend class InEdgeIt;
692 friend int NodeSet::id(Node v);
696 Node (Invalid i) { n=-1; }
697 bool operator==(const Node i) const {return n==i.n;}
698 bool operator!=(const Node i) const {return n!=i.n;}
699 bool operator<(const Node i) const {return n<i.n;}
702 class NodeIt : public Node {
704 friend class NodeSet;
706 NodeIt() : Node() { }
707 NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { }
708 NodeIt(Invalid i) : Node(i) { }
709 NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { }
710 NodeIt &operator++() {
720 bool operator==(const Edge i) const {return true;}
721 bool operator!=(const Edge i) const {return false;}
722 bool operator<(const Edge i) const {return false;}
725 class EdgeIt : public Edge {
727 EdgeIt(const NodeSet& G) : Edge() { }
728 EdgeIt(const NodeSet&, Edge) : Edge() { }
729 EdgeIt (Invalid i) : Edge(i) { }
730 EdgeIt() : Edge() { }
731 EdgeIt operator++() { return INVALID; }
734 class OutEdgeIt : public Edge {
735 friend class NodeSet;
737 OutEdgeIt() : Edge() { }
738 OutEdgeIt(const NodeSet&, Edge) : Edge() { }
739 OutEdgeIt (Invalid i) : Edge(i) { }
740 OutEdgeIt(const NodeSet& G,const Node v) : Edge() {}
741 OutEdgeIt operator++() { return INVALID; }
744 class InEdgeIt : public Edge {
745 friend class NodeSet;
747 InEdgeIt() : Edge() { }
748 InEdgeIt(const NodeSet&, Edge) : Edge() { }
749 InEdgeIt (Invalid i) : Edge(i) { }
750 InEdgeIt(const NodeSet& G,Node v) :Edge() {}
751 InEdgeIt operator++() { return INVALID; }
758 ///Graph structure using a node set of another graph.
760 ///This structure can be used to establish another graph over a node set
761 /// of an existing one. The node iterator will go through the nodes of the
762 /// original graph, and the NodeMap's of both graphs will convert to
765 ///\warning Adding or deleting nodes from the graph is not safe if an
766 ///\ref EdgeSet is currently attached to it!
768 ///\todo Make it possible to add/delete edges from the base graph
769 ///(and from \ref EdgeSet, as well)
771 ///\param GG The type of the graph which shares its node set with this class.
772 ///Its interface must conform to the
773 ///\ref skeleton::StaticGraph "StaticGraph" concept.
775 ///It conforms to the
776 ///\ref skeleton::ExtendableGraph "ExtendableGraph" concept.
777 ///\sa skeleton::ExtendableGraph.
779 template<typename GG>
782 typedef GG NodeGraphType;
794 typedef EdgeSet Graph;
796 int id(Node v) const;
798 class Node : public NodeGraphType::Node {
799 friend class EdgeSet;
802 friend class OutEdgeIt;
803 friend class InEdgeIt;
804 friend class SymEdge;
807 friend int EdgeSet::id(Node v) const;
809 Node() : NodeGraphType::Node() {}
810 Node (Invalid i) : NodeGraphType::Node(i) {}
811 Node(const typename NodeGraphType::Node &n) : NodeGraphType::Node(n) {}
814 class NodeIt : public NodeGraphType::NodeIt {
815 friend class EdgeSet;
817 NodeIt() : NodeGraphType::NodeIt() { }
818 NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { }
819 NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {}
820 NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
821 NodeIt(const typename NodeGraphType::NodeIt &n)
822 : NodeGraphType::NodeIt(n) {}
824 operator Node() { return Node(*this);}
826 { this->NodeGraphType::NodeIt::operator++(); return *this;}
830 //Edges are double linked.
831 //The free edges are only single linked using the "next_in" field.
834 int first_in,first_out;
835 NodeT() : first_in(-1), first_out(-1) { }
841 int prev_in, prev_out;
842 int next_in, next_out;
846 typename NodeGraphType::template NodeMap<NodeT> nodes;
848 std::vector<EdgeT> edges;
849 //The first free edge
863 // Create edge map registry.
864 CREATE_EDGE_MAP_REGISTRY;
866 CREATE_EDGE_MAP(ArrayMap);
868 // Import node maps from the NodeGraphType.
869 IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
876 ///Construates a new graph based on the nodeset of an existing one.
877 ///\param _G the base graph.
878 explicit EdgeSet(NodeGraphType &_G)
879 : G(_G), nodes(_G), edges(),
880 first_free_edge(-1) {}
883 ///Makes a copy of an EdgeSet.
884 ///It will be based on the same graph.
885 explicit EdgeSet(const EdgeSet &_g)
886 : G(_g.G), nodes(_g.G), edges(_g.edges),
887 first_free_edge(_g.first_free_edge) {}
890 int nodeNum() const { return G.nodeNum(); }
892 int edgeNum() const { return edges.size(); }
898 int maxNodeId() const { return G.maxNodeId(); }
903 int maxEdgeId() const { return edges.size()-1; }
905 Node tail(Edge e) const { return edges[e.n].tail; }
906 Node head(Edge e) const { return edges[e.n].head; }
908 NodeIt& first(NodeIt& v) const {
909 v=NodeIt(*this); return v; }
910 EdgeIt& first(EdgeIt& e) const {
911 e=EdgeIt(*this); return e; }
912 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
913 e=OutEdgeIt(*this,v); return e; }
914 InEdgeIt& first(InEdgeIt& e, const Node v) const {
915 e=InEdgeIt(*this,v); return e; }
919 /// The ID of a valid Node is a nonnegative integer not greater than
920 /// \ref maxNodeId(). The range of the ID's is not surely continuous
921 /// and the greatest node ID can be actually less then \ref maxNodeId().
923 /// The ID of the \ref INVALID node is -1.
924 ///\return The ID of the node \c v.
925 int id(Node v) { return G.id(v); }
928 /// The ID of a valid Edge is a nonnegative integer not greater than
929 /// \ref maxEdgeId(). The range of the ID's is not surely continuous
930 /// and the greatest edge ID can be actually less then \ref maxEdgeId().
932 /// The ID of the \ref INVALID edge is -1.
933 ///\return The ID of the edge \c e.
934 static int id(Edge e) { return e.n; }
936 /// Adds a new node to the graph.
937 Node addNode() { return G.addNode(); }
939 Edge addEdge(Node u, Node v) {
942 if(first_free_edge==-1)
945 edges.push_back(EdgeT());
949 first_free_edge = edges[n].next_in;
952 edges[n].tail = u; edges[n].head = v;
954 edges[n].next_out = nodes[u].first_out;
955 if(nodes[u].first_out != -1) edges[nodes[u].first_out].prev_out = n;
956 edges[n].next_in = nodes[v].first_in;
957 if(nodes[v].first_in != -1) edges[nodes[v].first_in].prev_in = n;
958 edges[n].prev_in = edges[n].prev_out = -1;
960 nodes[u].first_out = nodes[v].first_in = n;
964 //Update dynamic maps
970 /// Finds an edge between two nodes.
972 /// Finds an edge from node \c u to node \c v.
974 /// If \c prev is \ref INVALID (this is the default value), then
975 /// It finds the first edge from \c u to \c v. Otherwise it looks for
976 /// the next edge from \c u to \c v after \c prev.
977 /// \return The found edge or INVALID if there is no such an edge.
978 Edge findEdge(Node u,Node v, Edge prev = INVALID)
980 int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
981 while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
987 void eraseEdge(int n) {
989 if(edges[n].next_in!=-1)
990 edges[edges[n].next_in].prev_in = edges[n].prev_in;
991 if(edges[n].prev_in!=-1)
992 edges[edges[n].prev_in].next_in = edges[n].next_in;
993 else nodes[edges[n].head].first_in = edges[n].next_in;
995 if(edges[n].next_out!=-1)
996 edges[edges[n].next_out].prev_out = edges[n].prev_out;
997 if(edges[n].prev_out!=-1)
998 edges[edges[n].prev_out].next_out = edges[n].next_out;
999 else nodes[edges[n].tail].first_out = edges[n].next_out;
1001 edges[n].next_in = first_free_edge;
1002 first_free_edge = -1;
1004 //Update dynamic maps
1011 void erase(Edge e) { eraseEdge(e.n); }
1013 ///Clear all edges. (Doesn't clear the nodes!)
1023 friend class EdgeSet;
1024 template <typename T> friend class EdgeMap;
1027 friend class NodeIt;
1030 friend int EdgeSet::id(Edge e) const;
1032 Edge(int nn) {n=nn;}
1035 Edge (Invalid) { n=-1; }
1036 bool operator==(const Edge i) const {return n==i.n;}
1037 bool operator!=(const Edge i) const {return n!=i.n;}
1038 bool operator<(const Edge i) const {return n<i.n;}
1041 class EdgeIt : public Edge {
1042 friend class EdgeSet;
1043 template <typename T> friend class EdgeMap;
1047 EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) {
1050 m!=INVALID && G->nodes[m].first_in == -1; ++m);
1051 ///\bug AJJAJ! This is a non sense!!!!!!!
1052 this->n = m!=INVALID?-1:G->nodes[m].first_in;
1054 EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1055 EdgeIt (Invalid i) : Edge(i) { }
1056 EdgeIt() : Edge() { }
1059 ///\bug UNIMPLEMENTED!!!!!
1061 EdgeIt &operator++() {
1066 class OutEdgeIt : public Edge {
1068 friend class EdgeSet;
1070 OutEdgeIt() : Edge() { }
1071 OutEdgeIt (Invalid i) : Edge(i) { }
1072 OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1074 OutEdgeIt(const EdgeSet& _G,const Node v) :
1075 Edge(_G.nodes[v].first_out), G(&_G) { }
1076 OutEdgeIt &operator++() {
1077 Edge::n = G->edges[Edge::n].next_out;
1082 class InEdgeIt : public Edge {
1084 friend class EdgeSet;
1086 InEdgeIt() : Edge() { }
1087 InEdgeIt (Invalid i) : Edge(i) { }
1088 InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1089 InEdgeIt(const EdgeSet& _G,Node v)
1090 : Edge(_G.nodes[v].first_in), G(&_G) { }
1091 InEdgeIt &operator++() {
1092 Edge::n = G->edges[Edge::n].next_in;
1099 template<typename GG>
1100 inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
1106 #endif //HUGO_LIST_GRAPH_H