3 #ifndef HUGO_LIST_GRAPH_H
4 #define HUGO_LIST_GRAPH_H
8 ///\brief ListGraph, SymListGraph, NodeSet and EdgeSet classes.
13 #include <hugo/invalid.h>
15 #include <hugo/map_registry.h>
16 #include <hugo/array_map.h>
18 #include <hugo/sym_map.h>
20 #include <hugo/map_defines.h>
25 /// \addtogroup graphs
28 ///A list graph class.
30 ///This is a simple and fast erasable graph implementation.
33 ///\ref skeleton::ErasableGraph "ErasableGraph" concept.
34 ///\sa skeleton::ErasableGraph.
37 //Nodes are double linked.
38 //The free nodes are only single linked using the "next" field.
41 int first_in,first_out;
44 //Edges are double linked.
45 //The free edges are only single linked using the "next_in" field.
49 int prev_in, prev_out;
50 int next_in, next_out;
53 std::vector<NodeT> nodes;
58 std::vector<EdgeT> edges;
64 typedef ListGraph Graph;
77 // Create map registries.
78 CREATE_MAP_REGISTRIES;
79 // Create node and edge maps.
80 CREATE_MAPS(ArrayMap);
85 : nodes(), first_node(-1),
86 first_free_node(-1), edges(), first_free_edge(-1) {}
88 ListGraph(const ListGraph &_g)
89 : nodes(_g.nodes), first_node(_g.first_node),
90 first_free_node(_g.first_free_node), edges(_g.edges),
91 first_free_edge(_g.first_free_edge) {}
94 int nodeNum() const { return nodes.size(); }
96 int edgeNum() const { return edges.size(); }
98 ///Set the expected maximum number of edges.
100 ///With this function, it is possible to set the expected number of edges.
101 ///The use of this fasten the building of the graph and makes
102 ///it possible to avoid the superfluous memory allocation.
103 void reserveEdge(int n) { edges.reserve(n); };
109 int maxNodeId() const { return nodes.size()-1; }
114 int maxEdgeId() const { return edges.size()-1; }
116 Node tail(Edge e) const { return edges[e.n].tail; }
117 Node head(Edge e) const { return edges[e.n].head; }
119 NodeIt& first(NodeIt& v) const {
120 v=NodeIt(*this); return v; }
121 EdgeIt& first(EdgeIt& e) const {
122 e=EdgeIt(*this); return e; }
123 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
124 e=OutEdgeIt(*this,v); return e; }
125 InEdgeIt& first(InEdgeIt& e, const Node v) const {
126 e=InEdgeIt(*this,v); return e; }
130 /// The ID of a valid Node is a nonnegative integer not greater than
131 /// \ref maxNodeId(). The range of the ID's is not surely continuous
132 /// and the greatest node ID can be actually less then \ref maxNodeId().
134 /// The ID of the \ref INVALID node is -1.
135 ///\return The ID of the node \c v.
136 static int id(Node v) { return v.n; }
139 /// The ID of a valid Edge is a nonnegative integer not greater than
140 /// \ref maxEdgeId(). The range of the ID's is not surely continuous
141 /// and the greatest edge ID can be actually less then \ref maxEdgeId().
143 /// The ID of the \ref INVALID edge is -1.
144 ///\return The ID of the edge \c e.
145 static int id(Edge e) { return e.n; }
147 /// Adds a new node to the graph.
149 /// \warning It adds the new node to the front of the list.
150 /// (i.e. the lastly added node becomes the first.)
154 if(first_free_node==-1)
157 nodes.push_back(NodeT());
161 first_free_node = nodes[n].next;
164 nodes[n].next = first_node;
165 if(first_node != -1) nodes[first_node].prev = n;
169 nodes[n].first_in = nodes[n].first_out = -1;
173 //Update dynamic maps
179 Edge addEdge(Node u, Node v) {
182 if(first_free_edge==-1)
185 edges.push_back(EdgeT());
189 first_free_edge = edges[n].next_in;
192 edges[n].tail = u.n; edges[n].head = v.n;
194 edges[n].next_out = nodes[u.n].first_out;
195 if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n;
196 edges[n].next_in = nodes[v.n].first_in;
197 if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n;
198 edges[n].prev_in = edges[n].prev_out = -1;
200 nodes[u.n].first_out = nodes[v.n].first_in = n;
204 //Update dynamic maps
210 /// Finds an edge between two nodes.
212 /// Finds an edge from node \c u to node \c v.
214 /// If \c prev is \ref INVALID (this is the default value), then
215 /// It finds the first edge from \c u to \c v. Otherwise it looks for
216 /// the next edge from \c u to \c v after \c prev.
217 /// \return The found edge or INVALID if there is no such an edge.
218 Edge findEdge(Node u,Node v, Edge prev = INVALID)
220 int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
221 while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
227 void eraseEdge(int n) {
229 if(edges[n].next_in!=-1)
230 edges[edges[n].next_in].prev_in = edges[n].prev_in;
231 if(edges[n].prev_in!=-1)
232 edges[edges[n].prev_in].next_in = edges[n].next_in;
233 else nodes[edges[n].head].first_in = edges[n].next_in;
235 if(edges[n].next_out!=-1)
236 edges[edges[n].next_out].prev_out = edges[n].prev_out;
237 if(edges[n].prev_out!=-1)
238 edges[edges[n].prev_out].next_out = edges[n].next_out;
239 else nodes[edges[n].tail].first_out = edges[n].next_out;
241 edges[n].next_in = first_free_edge;
244 //Update dynamic maps
252 void erase(Node nn) {
256 while((m=nodes[n].first_in)!=-1) eraseEdge(m);
257 while((m=nodes[n].first_out)!=-1) eraseEdge(m);
259 if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
260 if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
261 else first_node = nodes[n].next;
263 nodes[n].next = first_free_node;
266 //Update dynamic maps
271 void erase(Edge e) { eraseEdge(e.n); }
278 first_node=first_free_node=first_free_edge=-1;
282 friend class ListGraph;
283 template <typename T> friend class NodeMap;
286 friend class OutEdgeIt;
287 friend class InEdgeIt;
288 friend class SymEdge;
292 friend int ListGraph::id(Node v);
296 Node (Invalid) { n=-1; }
297 bool operator==(const Node i) const {return n==i.n;}
298 bool operator!=(const Node i) const {return n!=i.n;}
299 bool operator<(const Node i) const {return n<i.n;}
301 // operator bool() { return n!=-1; }
304 class NodeIt : public Node {
306 friend class ListGraph;
308 NodeIt() : Node() { }
309 NodeIt(Invalid i) : Node(i) { }
310 NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
311 NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { }
312 NodeIt &operator++() {
317 // operator bool() { return Node::operator bool(); }
321 friend class ListGraph;
322 template <typename T> friend class EdgeMap;
324 friend class SymListGraph;
330 friend int ListGraph::id(Edge e);
333 /// An Edge with id \c n.
335 /// \bug It should be
336 /// obtained by a member function of the Graph.
340 Edge (Invalid) { n=-1; }
341 bool operator==(const Edge i) const {return n==i.n;}
342 bool operator!=(const Edge i) const {return n!=i.n;}
343 bool operator<(const Edge i) const {return n<i.n;}
345 // operator bool() { return n!=-1; }
348 class EdgeIt : public Edge {
350 friend class ListGraph;
352 EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
355 m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
356 n = (m==-1)?-1:_G.nodes[m].first_in;
358 EdgeIt (Invalid i) : Edge(i) { }
359 EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
360 EdgeIt() : Edge() { }
361 EdgeIt &operator++() {
362 if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
365 for(nn=G->nodes[G->edges[n].head].next;
366 nn!=-1 && G->nodes[nn].first_in == -1;
367 nn = G->nodes[nn].next) ;
368 n = (nn==-1)?-1:G->nodes[nn].first_in;
373 // operator bool() { return Edge::operator bool(); }
376 class OutEdgeIt : public Edge {
378 friend class ListGraph;
380 OutEdgeIt() : Edge() { }
381 OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
382 OutEdgeIt (Invalid i) : Edge(i) { }
384 OutEdgeIt(const ListGraph& _G,const Node v)
385 : Edge(_G.nodes[v.n].first_out), G(&_G) {}
386 OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
388 // operator bool() { return Edge::operator bool(); }
391 class InEdgeIt : public Edge {
393 friend class ListGraph;
395 InEdgeIt() : Edge() { }
396 InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
397 InEdgeIt (Invalid i) : Edge(i) { }
398 InEdgeIt(const ListGraph& _G,Node v)
399 : Edge(_G.nodes[v.n].first_in), G(&_G) { }
400 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
402 // operator bool() { return Edge::operator bool(); }
406 ///Graph for bidirectional edges.
408 ///The purpose of this graph structure is to handle graphs
409 ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
410 ///of oppositely directed edges.
411 ///There is a new edge map type called
412 ///\ref SymListGraph::SymEdgeMap "SymEdgeMap"
413 ///that complements this
415 ///storing shared values for the edge pairs. The usual
416 ///\ref Graph::EdgeMap "EdgeMap"
420 ///The oppositely directed edge can also be obtained easily
421 ///using \ref opposite.
423 ///Here erase(Edge) deletes a pair of edges.
425 ///\todo this date structure need some reconsiderations. Maybe it
426 ///should be implemented independently from ListGraph.
428 class SymListGraph : public ListGraph
432 typedef SymListGraph Graph;
434 // Create symmetric map registry.
435 CREATE_SYM_EDGE_MAP_REGISTRY;
436 // Create symmetric edge map.
437 CREATE_SYM_EDGE_MAP(ArrayMap);
439 SymListGraph() : ListGraph() { }
440 SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
441 ///Adds a pair of oppositely directed edges to the graph.
442 Edge addEdge(Node u, Node v)
444 Edge e = ListGraph::addEdge(u,v);
445 Edge f = ListGraph::addEdge(v,u);
446 sym_edge_maps.add(e);
447 sym_edge_maps.add(f);
452 void erase(Node n) { ListGraph::erase(n);}
453 ///The oppositely directed edge.
455 ///Returns the oppositely directed
456 ///pair of the edge \c e.
457 static Edge opposite(Edge e)
460 f.n = e.n - 2*(e.n%2) + 1;
464 ///Removes a pair of oppositely directed edges to the graph.
466 Edge f = opposite(e);
467 sym_edge_maps.erase(e);
468 sym_edge_maps.erase(f);
475 ///A graph class containing only nodes.
477 ///This class implements a graph structure without edges.
478 ///The most useful application of this class is to be the node set of an
479 ///\ref EdgeSet class.
482 ///the \ref skeleton::ExtendableGraph "ExtendableGraph" concept
483 ///with the exception that you cannot
484 ///add (or delete) edges. The usual edge iterators are exists, but they are
485 ///always \ref INVALID.
486 ///\sa skeleton::ExtendableGraph
490 //Nodes are double linked.
491 //The free nodes are only single linked using the "next" field.
494 int first_in,first_out;
499 std::vector<NodeT> nodes;
502 //The first free node
507 typedef NodeSet Graph;
519 // Create node map registry.
520 CREATE_NODE_MAP_REGISTRY;
522 CREATE_NODE_MAP(ArrayMap);
524 /// Creating empty map structure for edges.
525 template <typename Value>
528 EdgeMap(const Graph&) {}
529 EdgeMap(const Graph&, const Value&) {}
531 EdgeMap(const EdgeMap&) {}
532 template <typename CMap> EdgeMap(const CMap&) {}
534 EdgeMap& operator=(const EdgeMap&) {}
535 template <typename CMap> EdgeMap& operator=(const CMap&) {}
537 class ConstIterator {
539 bool operator==(const ConstIterator&) {return true;}
540 bool operator!=(const ConstIterator&) {return false;}
543 typedef ConstIterator Iterator;
545 Iterator begin() { return Iterator();}
546 Iterator end() { return Iterator();}
548 ConstIterator begin() const { return ConstIterator();}
549 ConstIterator end() const { return ConstIterator();}
555 ///Default constructor
557 : nodes(), first_node(-1), first_free_node(-1) {}
559 NodeSet(const NodeSet &_g)
560 : nodes(_g.nodes), first_node(_g.first_node),
561 first_free_node(_g.first_free_node) {}
564 int nodeNum() const { return nodes.size(); }
566 int edgeNum() const { return 0; }
572 int maxNodeId() const { return nodes.size()-1; }
577 int maxEdgeId() const { return 0; }
579 Node tail(Edge e) const { return INVALID; }
580 Node head(Edge e) const { return INVALID; }
582 NodeIt& first(NodeIt& v) const {
583 v=NodeIt(*this); return v; }
584 EdgeIt& first(EdgeIt& e) const {
585 e=EdgeIt(*this); return e; }
586 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
587 e=OutEdgeIt(*this,v); return e; }
588 InEdgeIt& first(InEdgeIt& e, const Node v) const {
589 e=InEdgeIt(*this,v); return e; }
593 /// The ID of a valid Node is a nonnegative integer not greater than
594 /// \ref maxNodeId(). The range of the ID's is not surely continuous
595 /// and the greatest node ID can be actually less then \ref maxNodeId().
597 /// The ID of the \ref INVALID node is -1.
598 ///\return The ID of the node \c v.
599 static int id(Node v) { return v.n; }
602 /// The ID of a valid Edge is a nonnegative integer not greater than
603 /// \ref maxEdgeId(). The range of the ID's is not surely continuous
604 /// and the greatest edge ID can be actually less then \ref maxEdgeId().
606 /// The ID of the \ref INVALID edge is -1.
607 ///\return The ID of the edge \c e.
608 static int id(Edge e) { return -1; }
610 /// Adds a new node to the graph.
612 /// \warning It adds the new node to the front of the list.
613 /// (i.e. the lastly added node becomes the first.)
617 if(first_free_node==-1)
620 nodes.push_back(NodeT());
624 first_free_node = nodes[n].next;
627 nodes[n].next = first_node;
628 if(first_node != -1) nodes[first_node].prev = n;
632 nodes[n].first_in = nodes[n].first_out = -1;
636 //Update dynamic maps
642 void erase(Node nn) {
645 if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
646 if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
647 else first_node = nodes[n].next;
649 nodes[n].next = first_free_node;
652 //Update dynamic maps
657 Edge findEdge(Node u,Node v, Edge prev = INVALID)
665 first_node = first_free_node = -1;
669 friend class NodeSet;
670 template <typename T> friend class NodeMap;
673 friend class OutEdgeIt;
674 friend class InEdgeIt;
678 friend int NodeSet::id(Node v);
682 Node (Invalid i) { n=-1; }
683 bool operator==(const Node i) const {return n==i.n;}
684 bool operator!=(const Node i) const {return n!=i.n;}
685 bool operator<(const Node i) const {return n<i.n;}
688 class NodeIt : public Node {
690 friend class NodeSet;
692 NodeIt() : Node() { }
693 NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { }
694 NodeIt(Invalid i) : Node(i) { }
695 NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { }
696 NodeIt &operator++() {
706 bool operator==(const Edge i) const {return true;}
707 bool operator!=(const Edge i) const {return false;}
708 bool operator<(const Edge i) const {return false;}
711 class EdgeIt : public Edge {
713 EdgeIt(const NodeSet& G) : Edge() { }
714 EdgeIt(const NodeSet&, Edge) : Edge() { }
715 EdgeIt (Invalid i) : Edge(i) { }
716 EdgeIt() : Edge() { }
717 EdgeIt operator++() { return INVALID; }
720 class OutEdgeIt : public Edge {
721 friend class NodeSet;
723 OutEdgeIt() : Edge() { }
724 OutEdgeIt(const NodeSet&, Edge) : Edge() { }
725 OutEdgeIt (Invalid i) : Edge(i) { }
726 OutEdgeIt(const NodeSet& G,const Node v) : Edge() {}
727 OutEdgeIt operator++() { return INVALID; }
730 class InEdgeIt : public Edge {
731 friend class NodeSet;
733 InEdgeIt() : Edge() { }
734 InEdgeIt(const NodeSet&, Edge) : Edge() { }
735 InEdgeIt (Invalid i) : Edge(i) { }
736 InEdgeIt(const NodeSet& G,Node v) :Edge() {}
737 InEdgeIt operator++() { return INVALID; }
744 ///Graph structure using a node set of another graph.
746 ///This structure can be used to establish another graph over a node set
747 /// of an existing one. The node iterator will go through the nodes of the
748 /// original graph, and the NodeMap's of both graphs will convert to
751 ///\warning Adding or deleting nodes from the graph is not safe if an
752 ///\ref EdgeSet is currently attached to it!
754 ///\todo Make it possible to add/delete edges from the base graph
755 ///(and from \ref EdgeSet, as well)
757 ///\param GG The type of the graph which shares its node set with this class.
758 ///Its interface must conform to the
759 ///\ref skeleton::StaticGraph "StaticGraph" concept.
761 ///It conforms to the
762 ///\ref skeleton::ExtendableGraph "ExtendableGraph" concept.
763 ///\sa skeleton::ExtendableGraph.
765 template<typename GG>
768 typedef GG NodeGraphType;
780 typedef EdgeSet Graph;
782 int id(Node v) const;
784 class Node : public NodeGraphType::Node {
785 friend class EdgeSet;
788 friend class OutEdgeIt;
789 friend class InEdgeIt;
790 friend class SymEdge;
793 friend int EdgeSet::id(Node v) const;
795 Node() : NodeGraphType::Node() {}
796 Node (Invalid i) : NodeGraphType::Node(i) {}
797 Node(const typename NodeGraphType::Node &n) : NodeGraphType::Node(n) {}
800 class NodeIt : public NodeGraphType::NodeIt {
801 friend class EdgeSet;
803 NodeIt() : NodeGraphType::NodeIt() { }
804 NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { }
805 NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {}
806 NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
807 NodeIt(const typename NodeGraphType::NodeIt &n)
808 : NodeGraphType::NodeIt(n) {}
810 operator Node() { return Node(*this);}
812 { this->NodeGraphType::NodeIt::operator++(); return *this;}
816 //Edges are double linked.
817 //The free edges are only single linked using the "next_in" field.
820 int first_in,first_out;
821 NodeT() : first_in(-1), first_out(-1) { }
827 int prev_in, prev_out;
828 int next_in, next_out;
832 typename NodeGraphType::template NodeMap<NodeT> nodes;
834 std::vector<EdgeT> edges;
835 //The first free edge
849 // Create edge map registry.
850 CREATE_EDGE_MAP_REGISTRY;
852 CREATE_EDGE_MAP(ArrayMap);
854 // Import node maps from the NodeGraphType.
855 IMPORT_NODE_MAP(NodeGraphType, graph.G, EdgeSet, graph);
862 ///Construates a new graph based on the nodeset of an existing one.
863 ///\param _G the base graph.
864 explicit EdgeSet(NodeGraphType &_G)
865 : G(_G), nodes(_G), edges(),
866 first_free_edge(-1) {}
869 ///Makes a copy of an EdgeSet.
870 ///It will be based on the same graph.
871 explicit EdgeSet(const EdgeSet &_g)
872 : G(_g.G), nodes(_g.G), edges(_g.edges),
873 first_free_edge(_g.first_free_edge) {}
876 int nodeNum() const { return G.nodeNum(); }
878 int edgeNum() const { return edges.size(); }
884 int maxNodeId() const { return G.maxNodeId(); }
889 int maxEdgeId() const { return edges.size()-1; }
891 Node tail(Edge e) const { return edges[e.n].tail; }
892 Node head(Edge e) const { return edges[e.n].head; }
894 NodeIt& first(NodeIt& v) const {
895 v=NodeIt(*this); return v; }
896 EdgeIt& first(EdgeIt& e) const {
897 e=EdgeIt(*this); return e; }
898 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
899 e=OutEdgeIt(*this,v); return e; }
900 InEdgeIt& first(InEdgeIt& e, const Node v) const {
901 e=InEdgeIt(*this,v); return e; }
905 /// The ID of a valid Node is a nonnegative integer not greater than
906 /// \ref maxNodeId(). The range of the ID's is not surely continuous
907 /// and the greatest node ID can be actually less then \ref maxNodeId().
909 /// The ID of the \ref INVALID node is -1.
910 ///\return The ID of the node \c v.
911 int id(Node v) { return G.id(v); }
914 /// The ID of a valid Edge is a nonnegative integer not greater than
915 /// \ref maxEdgeId(). The range of the ID's is not surely continuous
916 /// and the greatest edge ID can be actually less then \ref maxEdgeId().
918 /// The ID of the \ref INVALID edge is -1.
919 ///\return The ID of the edge \c e.
920 static int id(Edge e) { return e.n; }
922 /// Adds a new node to the graph.
923 Node addNode() { return G.addNode(); }
925 Edge addEdge(Node u, Node v) {
928 if(first_free_edge==-1)
931 edges.push_back(EdgeT());
935 first_free_edge = edges[n].next_in;
938 edges[n].tail = u; edges[n].head = v;
940 edges[n].next_out = nodes[u].first_out;
941 if(nodes[u].first_out != -1) edges[nodes[u].first_out].prev_out = n;
942 edges[n].next_in = nodes[v].first_in;
943 if(nodes[v].first_in != -1) edges[nodes[v].first_in].prev_in = n;
944 edges[n].prev_in = edges[n].prev_out = -1;
946 nodes[u].first_out = nodes[v].first_in = n;
950 //Update dynamic maps
956 /// Finds an edge between two nodes.
958 /// Finds an edge from node \c u to node \c v.
960 /// If \c prev is \ref INVALID (this is the default value), then
961 /// It finds the first edge from \c u to \c v. Otherwise it looks for
962 /// the next edge from \c u to \c v after \c prev.
963 /// \return The found edge or INVALID if there is no such an edge.
964 Edge findEdge(Node u,Node v, Edge prev = INVALID)
966 int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
967 while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
973 void eraseEdge(int n) {
975 if(edges[n].next_in!=-1)
976 edges[edges[n].next_in].prev_in = edges[n].prev_in;
977 if(edges[n].prev_in!=-1)
978 edges[edges[n].prev_in].next_in = edges[n].next_in;
979 else nodes[edges[n].head].first_in = edges[n].next_in;
981 if(edges[n].next_out!=-1)
982 edges[edges[n].next_out].prev_out = edges[n].prev_out;
983 if(edges[n].prev_out!=-1)
984 edges[edges[n].prev_out].next_out = edges[n].next_out;
985 else nodes[edges[n].tail].first_out = edges[n].next_out;
987 edges[n].next_in = first_free_edge;
988 first_free_edge = -1;
990 //Update dynamic maps
997 void erase(Edge e) { eraseEdge(e.n); }
999 ///Clear all edges. (Doesn't clear the nodes!)
1009 friend class EdgeSet;
1010 template <typename T> friend class EdgeMap;
1013 friend class NodeIt;
1016 friend int EdgeSet::id(Edge e) const;
1018 Edge(int nn) {n=nn;}
1021 Edge (Invalid) { n=-1; }
1022 bool operator==(const Edge i) const {return n==i.n;}
1023 bool operator!=(const Edge i) const {return n!=i.n;}
1024 bool operator<(const Edge i) const {return n<i.n;}
1027 class EdgeIt : public Edge {
1028 friend class EdgeSet;
1029 template <typename T> friend class EdgeMap;
1033 EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) {
1036 m!=INVALID && G->nodes[m].first_in == -1; ++m);
1037 ///\bug AJJAJ! This is a non sense!!!!!!!
1038 this->n = m!=INVALID?-1:G->nodes[m].first_in;
1040 EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1041 EdgeIt (Invalid i) : Edge(i) { }
1042 EdgeIt() : Edge() { }
1045 ///\bug UNIMPLEMENTED!!!!!
1047 EdgeIt &operator++() {
1052 class OutEdgeIt : public Edge {
1054 friend class EdgeSet;
1056 OutEdgeIt() : Edge() { }
1057 OutEdgeIt (Invalid i) : Edge(i) { }
1058 OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1060 OutEdgeIt(const EdgeSet& _G,const Node v) :
1061 Edge(_G.nodes[v].first_out), G(&_G) { }
1062 OutEdgeIt &operator++() {
1063 Edge::n = G->edges[Edge::n].next_out;
1068 class InEdgeIt : public Edge {
1070 friend class EdgeSet;
1072 InEdgeIt() : Edge() { }
1073 InEdgeIt (Invalid i) : Edge(i) { }
1074 InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1075 InEdgeIt(const EdgeSet& _G,Node v)
1076 : Edge(_G.nodes[v].first_in), G(&_G) { }
1077 InEdgeIt &operator++() {
1078 Edge::n = G->edges[Edge::n].next_in;
1085 template<typename GG>
1086 inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
1092 #endif //HUGO_LIST_GRAPH_H