Bug: This file must be updated.
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/default_map_factory.h>
18 #include <hugo/sym_map_factory.h>
20 #include <hugo/map_defines.h>
25 /// \addtogroup graphs
28 // class SymListGraph;
30 ///A list graph class.
32 ///This is a simple and fast erasable graph implementation.
34 ///It conforms to the graph interface documented under
35 ///the description of \ref GraphSkeleton.
36 ///\sa \ref GraphSkeleton.
39 //Nodes are double linked.
40 //The free nodes are only single linked using the "next" field.
43 int first_in,first_out;
47 //Edges are double linked.
48 //The free edges are only single linked using the "next_in" field.
52 int prev_in, prev_out;
53 int next_in, next_out;
54 //FIXME: is this necessary?
55 // EdgeT() : next_in(-1), next_out(-1) prev_in(-1), prev_out(-1) {}
58 std::vector<NodeT> nodes;
63 std::vector<EdgeT> edges;
69 typedef ListGraph Graph;
82 CREATE_MAP_REGISTRIES;
83 CREATE_MAPS(DefaultMapFactory);
88 : nodes(), first_node(-1),
89 first_free_node(-1), edges(), first_free_edge(-1) {}
91 ListGraph(const ListGraph &_g)
92 : nodes(_g.nodes), first_node(_g.first_node),
93 first_free_node(_g.first_free_node), edges(_g.edges),
94 first_free_edge(_g.first_free_edge) {}
96 int nodeNum() const { return nodes.size(); } //FIXME: What is this?
97 int edgeNum() const { return edges.size(); } //FIXME: What is this?
99 ///Set the expected number of edges
101 ///With this function, it is possible to set the expected number of edges.
102 ///The use of this fasten the building of the graph and makes
103 ///it possible to avoid the superfluous memory allocation.
104 void reserveEdge(int n) { edges.reserve(n); };
106 ///\bug This function does something different than
107 ///its name would suggests...
108 int maxNodeId() const { return nodes.size(); } //FIXME: What is this?
109 ///\bug This function does something different than
110 ///its name would suggests...
111 int maxEdgeId() const { return edges.size(); } //FIXME: What is this?
113 Node tail(Edge e) const { return edges[e.n].tail; }
114 Node head(Edge e) const { return edges[e.n].head; }
116 NodeIt& first(NodeIt& v) const {
117 v=NodeIt(*this); return v; }
118 EdgeIt& first(EdgeIt& e) const {
119 e=EdgeIt(*this); return e; }
120 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
121 e=OutEdgeIt(*this,v); return e; }
122 InEdgeIt& first(InEdgeIt& e, const Node v) const {
123 e=InEdgeIt(*this,v); return e; }
125 static int id(Node v) { return v.n; }
126 static int id(Edge e) { return e.n; }
128 /// Adds a new node to the graph.
130 /// \todo It adds the nodes in a reversed order.
131 /// (i.e. the lastly added node becomes the first.)
135 if(first_free_node==-1)
138 nodes.push_back(NodeT());
142 first_free_node = nodes[n].next;
145 nodes[n].next = first_node;
146 if(first_node != -1) nodes[first_node].prev = n;
150 nodes[n].first_in = nodes[n].first_out = -1;
154 //Update dynamic maps
160 Edge addEdge(Node u, Node v) {
163 if(first_free_edge==-1)
166 edges.push_back(EdgeT());
170 first_free_edge = edges[n].next_in;
173 edges[n].tail = u.n; edges[n].head = v.n;
175 edges[n].next_out = nodes[u.n].first_out;
176 if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n;
177 edges[n].next_in = nodes[v.n].first_in;
178 if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n;
179 edges[n].prev_in = edges[n].prev_out = -1;
181 nodes[u.n].first_out = nodes[v.n].first_in = n;
185 //Update dynamic maps
191 /// Finds an edge between two nodes.
193 /// Finds an edge from node \c u to node \c v.
195 /// If \c prev is \ref INVALID (this is the default value), then
196 /// It finds the first edge from \c u to \c v. Otherwise it looks for
197 /// the next edge from \c u to \c v after \c prev.
198 /// \return The found edge or INVALID if there is no such an edge.
199 Edge findEdge(Node u,Node v, Edge prev = INVALID)
201 int e = (prev.n==-1)? nodes[u.n].first_out : edges[prev.n].next_out;
202 while(e!=-1 && edges[e].tail!=v.n) e = edges[e].next_out;
208 void eraseEdge(int n) {
210 if(edges[n].next_in!=-1)
211 edges[edges[n].next_in].prev_in = edges[n].prev_in;
212 if(edges[n].prev_in!=-1)
213 edges[edges[n].prev_in].next_in = edges[n].next_in;
214 else nodes[edges[n].head].first_in = edges[n].next_in;
216 if(edges[n].next_out!=-1)
217 edges[edges[n].next_out].prev_out = edges[n].prev_out;
218 if(edges[n].prev_out!=-1)
219 edges[edges[n].prev_out].next_out = edges[n].next_out;
220 else nodes[edges[n].tail].first_out = edges[n].next_out;
222 edges[n].next_in = first_free_edge;
225 //Update dynamic maps
233 void erase(Node nn) {
237 while((m=nodes[n].first_in)!=-1) eraseEdge(m);
238 while((m=nodes[n].first_out)!=-1) eraseEdge(m);
240 if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
241 if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
242 else first_node = nodes[n].next;
244 nodes[n].next = first_free_node;
247 //Update dynamic maps
252 void erase(Edge e) { eraseEdge(e.n); }
259 first_node=first_free_node=first_free_edge=-1;
263 friend class ListGraph;
264 template <typename T> friend class NodeMap;
267 friend class OutEdgeIt;
268 friend class InEdgeIt;
269 friend class SymEdge;
273 friend int ListGraph::id(Node v);
277 Node (Invalid) { n=-1; }
278 bool operator==(const Node i) const {return n==i.n;}
279 bool operator!=(const Node i) const {return n!=i.n;}
280 bool operator<(const Node i) const {return n<i.n;}
282 // operator bool() { return n!=-1; }
285 class NodeIt : public Node {
287 friend class ListGraph;
289 NodeIt() : Node() { }
290 NodeIt(Invalid i) : Node(i) { }
291 NodeIt(const ListGraph& _G) : Node(_G.first_node), G(&_G) { }
292 ///\todo Undocumented conversion Node -\> NodeIt.
293 NodeIt(const ListGraph& _G,Node n) : Node(n), G(&_G) { }
294 NodeIt &operator++() {
299 // operator bool() { return Node::operator bool(); }
303 friend class ListGraph;
304 template <typename T> friend class EdgeMap;
306 //template <typename T> friend class SymListGraph::SymEdgeMap;
307 //friend Edge SymListGraph::opposite(Edge) const;
313 friend int ListGraph::id(Edge e);
316 /// An Edge with id \c n.
318 /// \bug It should be
319 /// obtained by a member function of the Graph.
323 Edge (Invalid) { n=-1; }
324 bool operator==(const Edge i) const {return n==i.n;}
325 bool operator!=(const Edge i) const {return n!=i.n;}
326 bool operator<(const Edge i) const {return n<i.n;}
327 ///\bug This is a workaround until somebody tells me how to
328 ///make class \c SymListGraph::SymEdgeMap friend of Edge
329 int &idref() {return n;}
330 const int &idref() const {return n;}
332 // operator bool() { return n!=-1; }
335 class EdgeIt : public Edge {
337 friend class ListGraph;
339 EdgeIt(const ListGraph& _G) : Edge(), G(&_G) {
342 m!=-1 && _G.nodes[m].first_in == -1; m = _G.nodes[m].next);
343 n = (m==-1)?-1:_G.nodes[m].first_in;
345 EdgeIt (Invalid i) : Edge(i) { }
346 EdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
347 EdgeIt() : Edge() { }
348 ///\bug This is a workaround until somebody tells me how to
349 ///make class \c SymListGraph::SymEdgeMap friend of Edge
350 int &idref() {return n;}
351 EdgeIt &operator++() {
352 if(G->edges[n].next_in!=-1) n=G->edges[n].next_in;
355 for(nn=G->nodes[G->edges[n].head].next;
356 nn!=-1 && G->nodes[nn].first_in == -1;
357 nn = G->nodes[nn].next) ;
358 n = (nn==-1)?-1:G->nodes[nn].first_in;
363 // operator bool() { return Edge::operator bool(); }
366 class OutEdgeIt : public Edge {
368 friend class ListGraph;
370 OutEdgeIt() : Edge() { }
371 OutEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
372 OutEdgeIt (Invalid i) : Edge(i) { }
374 OutEdgeIt(const ListGraph& _G,const Node v)
375 : Edge(_G.nodes[v.n].first_out), G(&_G) {}
376 OutEdgeIt &operator++() { n=G->edges[n].next_out; return *this; }
378 // operator bool() { return Edge::operator bool(); }
381 class InEdgeIt : public Edge {
383 friend class ListGraph;
385 InEdgeIt() : Edge() { }
386 InEdgeIt(const ListGraph& _G, Edge e) : Edge(e), G(&_G) { }
387 InEdgeIt (Invalid i) : Edge(i) { }
388 InEdgeIt(const ListGraph& _G,Node v)
389 : Edge(_G.nodes[v.n].first_in), G(&_G) { }
390 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
392 // operator bool() { return Edge::operator bool(); }
396 ///Graph for bidirectional edges.
398 ///The purpose of this graph structure is to handle graphs
399 ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair
400 ///of oppositely directed edges.
401 ///There is a new edge map type called
402 ///\ref SymListGraph::SymEdgeMap "SymEdgeMap"
403 ///that complements this
405 ///storing shared values for the edge pairs. The usual
406 ///\ref GraphSkeleton::EdgeMap "EdgeMap"
410 ///The oppositely directed edge can also be obtained easily
411 ///using \ref opposite.
413 ///Here erase(Edge) deletes a pair of edges.
415 ///\todo this date structure need some reconsiderations. Maybe it
416 ///should be implemented independently from ListGraph.
418 class SymListGraph : public ListGraph
422 typedef SymListGraph Graph;
424 KEEP_NODE_MAP(ListGraph);
425 KEEP_EDGE_MAP(ListGraph);
427 CREATE_SYM_EDGE_MAP_REGISTRY;
428 CREATE_SYM_EDGE_MAP_FACTORY(DefaultMapFactory);
429 IMPORT_SYM_EDGE_MAP(SymEdgeMapFactory);
431 SymListGraph() : ListGraph() { }
432 SymListGraph(const ListGraph &_g) : ListGraph(_g) { }
433 ///Adds a pair of oppositely directed edges to the graph.
434 Edge addEdge(Node u, Node v)
436 Edge e = ListGraph::addEdge(u,v);
437 Edge f = ListGraph::addEdge(v,u);
438 sym_edge_maps.add(e);
439 sym_edge_maps.add(f);
444 void erase(Node n) { ListGraph::erase(n);}
445 ///The oppositely directed edge.
447 ///Returns the oppositely directed
448 ///pair of the edge \c e.
449 static Edge opposite(Edge e)
452 f.idref() = e.idref() - 2*(e.idref()%2) + 1;
456 ///Removes a pair of oppositely directed edges to the graph.
458 Edge f = opposite(e);
459 sym_edge_maps.erase(e);
460 sym_edge_maps.erase(f);
467 ///A graph class containing only nodes.
469 ///This class implements a graph structure without edges.
470 ///The most useful application of this class is to be the node set of an
471 ///\ref EdgeSet class.
473 ///It conforms to the graph interface documented under
474 ///the description of \ref GraphSkeleton with the exception that you cannot
475 ///add (or delete) edges. The usual edge iterators are exists, but they are
476 ///always \ref INVALID.
477 ///\sa \ref GraphSkeleton
481 //Nodes are double linked.
482 //The free nodes are only single linked using the "next" field.
485 int first_in,first_out;
490 std::vector<NodeT> nodes;
493 //The first free node
498 typedef NodeSet Graph;
510 CREATE_MAP_REGISTRIES;
511 CREATE_MAPS(DefaultMapFactory);
515 ///Default constructor
517 : nodes(), first_node(-1), first_free_node(-1) {}
519 NodeSet(const NodeSet &_g)
520 : nodes(_g.nodes), first_node(_g.first_node),
521 first_free_node(_g.first_free_node) {}
523 int nodeNum() const { return nodes.size(); } //FIXME: What is this?
524 int edgeNum() const { return 0; } //FIXME: What is this?
526 ///\bug This function does something different than
527 ///its name would suggests...
528 int maxNodeId() const { return nodes.size(); } //FIXME: What is this?
529 ///\bug This function does something different than
530 ///its name would suggests...
531 int maxEdgeId() const { return 0; } //FIXME: What is this?
533 Node tail(Edge e) const { return INVALID; }
534 Node head(Edge e) const { return INVALID; }
536 NodeIt& first(NodeIt& v) const {
537 v=NodeIt(*this); return v; }
538 EdgeIt& first(EdgeIt& e) const {
539 e=EdgeIt(*this); return e; }
540 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
541 e=OutEdgeIt(*this,v); return e; }
542 InEdgeIt& first(InEdgeIt& e, const Node v) const {
543 e=InEdgeIt(*this,v); return e; }
545 int id(Node v) const { return v.n; }
546 int id(Edge e) const { return -1; }
548 /// Adds a new node to the graph.
550 /// \todo It adds the nodes in a reversed order.
551 /// (i.e. the lastly added node becomes the first.)
555 if(first_free_node==-1)
558 nodes.push_back(NodeT());
562 first_free_node = nodes[n].next;
565 nodes[n].next = first_node;
566 if(first_node != -1) nodes[first_node].prev = n;
570 nodes[n].first_in = nodes[n].first_out = -1;
574 //Update dynamic maps
580 void erase(Node nn) {
583 if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev;
584 if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next;
585 else first_node = nodes[n].next;
587 nodes[n].next = first_free_node;
590 //Update dynamic maps
595 Edge findEdge(Node u,Node v, Edge prev = INVALID)
603 first_node = first_free_node = -1;
607 friend class NodeSet;
608 template <typename T> friend class NodeMap;
611 friend class OutEdgeIt;
612 friend class InEdgeIt;
616 friend int NodeSet::id(Node v) const;
620 Node (Invalid i) { n=-1; }
621 bool operator==(const Node i) const {return n==i.n;}
622 bool operator!=(const Node i) const {return n!=i.n;}
623 bool operator<(const Node i) const {return n<i.n;}
626 class NodeIt : public Node {
628 friend class NodeSet;
630 NodeIt() : Node() { }
631 NodeIt(const NodeSet& _G,Node n) : Node(n), G(&_G) { }
632 NodeIt(Invalid i) : Node(i) { }
633 NodeIt(const NodeSet& _G) : Node(_G.first_node), G(&_G) { }
634 NodeIt &operator++() {
641 //friend class NodeSet;
642 //template <typename T> friend class EdgeMap;
644 //template <typename T> friend class SymNodeSet::SymEdgeMap;
645 //friend Edge SymNodeSet::opposite(Edge) const;
647 // friend class Node;
648 // friend class NodeIt;
650 //friend int NodeSet::id(Edge e) const;
655 bool operator==(const Edge i) const {return true;}
656 bool operator!=(const Edge i) const {return false;}
657 bool operator<(const Edge i) const {return false;}
658 ///\bug This is a workaround until somebody tells me how to
659 ///make class \c SymNodeSet::SymEdgeMap friend of Edge
660 // int idref() {return -1;}
661 // int idref() const {return -1;}
664 class EdgeIt : public Edge {
665 //friend class NodeSet;
667 EdgeIt(const NodeSet& G) : Edge() { }
668 EdgeIt(const NodeSet&, Edge) : Edge() { }
669 EdgeIt (Invalid i) : Edge(i) { }
670 EdgeIt() : Edge() { }
671 ///\bug This is a workaround until somebody tells me how to
672 ///make class \c SymNodeSet::SymEdgeMap friend of Edge
673 // int idref() {return -1;}
674 EdgeIt operator++() { return INVALID; }
677 class OutEdgeIt : public Edge {
678 friend class NodeSet;
680 OutEdgeIt() : Edge() { }
681 OutEdgeIt(const NodeSet&, Edge) : Edge() { }
682 OutEdgeIt (Invalid i) : Edge(i) { }
683 OutEdgeIt(const NodeSet& G,const Node v) : Edge() {}
684 OutEdgeIt operator++() { return INVALID; }
687 class InEdgeIt : public Edge {
688 friend class NodeSet;
690 InEdgeIt() : Edge() { }
691 InEdgeIt(const NodeSet&, Edge) : Edge() { }
692 InEdgeIt (Invalid i) : Edge(i) { }
693 InEdgeIt(const NodeSet& G,Node v) :Edge() {}
694 InEdgeIt operator++() { return INVALID; }
701 ///Graph structure using a node set of another graph.
703 ///This structure can be used to establish another graph over a node set
704 /// of an existing one. The node iterator will go through the nodes of the
705 /// original graph, and the NodeMap's of both graphs will convert to
708 ///\warning Adding or deleting nodes from the graph is not safe if an
709 ///\ref EdgeSet is currently attached to it!
711 ///\todo Make it possible to add/delete edges from the base graph
712 ///(and from \ref EdgeSet, as well)
714 ///\param GG The type of the graph which shares its node set with this class.
715 ///Its interface must conform with \ref GraphSkeleton.
717 ///It conforms to the graph interface documented under
718 ///the description of \ref GraphSkeleton.
719 ///\sa \ref GraphSkeleton.
721 template<typename GG>
724 typedef GG NodeGraphType;
736 typedef EdgeSet Graph;
738 int id(Node v) const;
740 class Node : public NodeGraphType::Node {
741 friend class EdgeSet;
742 // template <typename T> friend class NodeMap;
745 friend class OutEdgeIt;
746 friend class InEdgeIt;
747 friend class SymEdge;
750 friend int EdgeSet::id(Node v) const;
751 // Node(int nn) {n=nn;}
753 Node() : NodeGraphType::Node() {}
754 Node (Invalid i) : NodeGraphType::Node(i) {}
755 Node(const typename NodeGraphType::Node &n) : NodeGraphType::Node(n) {}
758 class NodeIt : public NodeGraphType::NodeIt {
759 friend class EdgeSet;
761 NodeIt() : NodeGraphType::NodeIt() { }
762 NodeIt(const EdgeSet& _G,Node n) : NodeGraphType::NodeIt(_G.G,n) { }
763 NodeIt (Invalid i) : NodeGraphType::NodeIt(i) {}
764 NodeIt(const EdgeSet& _G) : NodeGraphType::NodeIt(_G.G) { }
765 NodeIt(const typename NodeGraphType::NodeIt &n)
766 : NodeGraphType::NodeIt(n) {}
768 operator Node() { return Node(*this);}
770 { this->NodeGraphType::NodeIt::operator++(); return *this;}
774 //Edges are double linked.
775 //The free edges are only single linked using the "next_in" field.
778 int first_in,first_out;
779 NodeT() : first_in(-1), first_out(-1) { }
785 int prev_in, prev_out;
786 int next_in, next_out;
790 typename NodeGraphType::template NodeMap<NodeT> nodes;
792 std::vector<EdgeT> edges;
793 //The first free edge
807 CREATE_EDGE_MAP_REGISTRY;
808 CREATE_EDGE_MAP_FACTORY(DefaultMapFactory);
809 IMPORT_EDGE_MAP(EdgeMapFactory);
816 ///Construates a new graph based on the nodeset of an existing one.
817 ///\param _G the base graph.
818 ///\todo It looks like a copy constructor, but it isn't.
819 EdgeSet(NodeGraphType &_G)
820 : G(_G), nodes(_G), edges(),
821 first_free_edge(-1) {}
824 ///Makes a copy of an EdgeSet.
825 ///It will be based on the same graph.
826 EdgeSet(const EdgeSet &_g)
827 : G(_g.G), nodes(_g.G), edges(_g.edges),
828 first_free_edge(_g.first_free_edge) {}
830 int nodeNum() const { return G.nodeNum(); } //FIXME: What is this?
831 int edgeNum() const { return edges.size(); } //FIXME: What is this?
833 ///\bug This function does something different than
834 ///its name would suggests...
835 int maxNodeId() const { return G.maxNodeId(); } //FIXME: What is this?
836 ///\bug This function does something different than
837 ///its name would suggests...
838 int maxEdgeId() const { return edges.size(); } //FIXME: What is this?
840 Node tail(Edge e) const { return edges[e.n].tail; }
841 Node head(Edge e) const { return edges[e.n].head; }
843 NodeIt& first(NodeIt& v) const {
844 v=NodeIt(*this); return v; }
845 EdgeIt& first(EdgeIt& e) const {
846 e=EdgeIt(*this); return e; }
847 OutEdgeIt& first(OutEdgeIt& e, const Node v) const {
848 e=OutEdgeIt(*this,v); return e; }
849 InEdgeIt& first(InEdgeIt& e, const Node v) const {
850 e=InEdgeIt(*this,v); return e; }
852 int id(Edge e) const { return e.n; }
854 /// Adds a new node to the graph.
855 Node addNode() { return G.addNode(); }
857 Edge addEdge(Node u, Node v) {
860 if(first_free_edge==-1)
863 edges.push_back(EdgeT());
867 first_free_edge = edges[n].next_in;
870 edges[n].tail = u; edges[n].head = v;
872 edges[n].next_out = nodes[u].first_out;
873 if(nodes[u].first_out != -1) edges[nodes[u].first_out].prev_out = n;
874 edges[n].next_in = nodes[v].first_in;
875 if(nodes[v].first_in != -1) edges[nodes[v].first_in].prev_in = n;
876 edges[n].prev_in = edges[n].prev_out = -1;
878 nodes[u].first_out = nodes[v].first_in = n;
882 //Update dynamic maps
888 /// Finds an edge between two nodes.
890 /// Finds an edge from node \c u to node \c v.
892 /// If \c prev is \ref INVALID (this is the default value), then
893 /// It finds the first edge from \c u to \c v. Otherwise it looks for
894 /// the next edge from \c u to \c v after \c prev.
895 /// \return The found edge or INVALID if there is no such an edge.
896 Edge findEdge(Node u,Node v, Edge prev = INVALID)
898 int e = (prev.n==-1)? nodes[u].first_out : edges[prev.n].next_out;
899 while(e!=-1 && edges[e].tail!=v) e = edges[e].next_out;
905 void eraseEdge(int n) {
907 if(edges[n].next_in!=-1)
908 edges[edges[n].next_in].prev_in = edges[n].prev_in;
909 if(edges[n].prev_in!=-1)
910 edges[edges[n].prev_in].next_in = edges[n].next_in;
911 else nodes[edges[n].head].first_in = edges[n].next_in;
913 if(edges[n].next_out!=-1)
914 edges[edges[n].next_out].prev_out = edges[n].prev_out;
915 if(edges[n].prev_out!=-1)
916 edges[edges[n].prev_out].next_out = edges[n].next_out;
917 else nodes[edges[n].tail].first_out = edges[n].next_out;
919 edges[n].next_in = first_free_edge;
920 first_free_edge = -1;
922 //Update dynamic maps
929 // void erase(Node nn) {
932 // while((m=nodes[n].first_in)!=-1) eraseEdge(m);
933 // while((m=nodes[n].first_out)!=-1) eraseEdge(m);
936 void erase(Edge e) { eraseEdge(e.n); }
938 ///Clear all edges. (Doesn't clear the nodes!)
948 friend class EdgeSet;
949 template <typename T> friend class EdgeMap;
954 ///\bug It should be at least protected
958 friend int EdgeSet::id(Edge e) const;
963 Edge (Invalid) { n=-1; }
964 bool operator==(const Edge i) const {return n==i.n;}
965 bool operator!=(const Edge i) const {return n!=i.n;}
966 bool operator<(const Edge i) const {return n<i.n;}
967 ///\bug This is a workaround until somebody tells me how to
968 ///make class \c SymEdgeSet::SymEdgeMap friend of Edge
969 int &idref() {return n;}
970 const int &idref() const {return n;}
973 class EdgeIt : public Edge {
974 friend class EdgeSet;
975 template <typename T> friend class EdgeMap;
979 EdgeIt(const EdgeSet& _G) : Edge(), G(&_G) {
980 // typename NodeGraphType::Node m;
983 m!=INVALID && G->nodes[m].first_in == -1; ++m);
984 ///\bug AJJAJ! This is a non sense!!!!!!!
985 this->n = m!=INVALID?-1:G->nodes[m].first_in;
987 EdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
988 EdgeIt (Invalid i) : Edge(i) { }
989 EdgeIt() : Edge() { }
992 ///\bug UNIMPLEMENTED!!!!!
994 EdgeIt &operator++() {
997 ///\bug This is a workaround until somebody tells me how to
998 ///make class \c SymEdgeSet::SymEdgeMap friend of Edge
999 int &idref() {return this->n;}
1002 class OutEdgeIt : public Edge {
1004 friend class EdgeSet;
1006 OutEdgeIt() : Edge() { }
1007 OutEdgeIt (Invalid i) : Edge(i) { }
1008 OutEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1010 OutEdgeIt(const EdgeSet& _G,const Node v) :
1011 Edge(_G.nodes[v].first_out), G(&_G) { }
1012 OutEdgeIt &operator++() { n = G->edges[n].next_out; return *this; }
1015 class InEdgeIt : public Edge {
1017 friend class EdgeSet;
1019 InEdgeIt() : Edge() { }
1020 InEdgeIt (Invalid i) : Edge(i) { }
1021 InEdgeIt(const EdgeSet& _G, Edge e) : Edge(e), G(&_G) { }
1022 InEdgeIt(const EdgeSet& _G,Node v)
1023 : Edge(_G.nodes[v].first_in), G(&_G) { }
1024 InEdgeIt &operator++() { n=G->edges[n].next_in; return *this; }
1028 template <typename V> class NodeMap
1029 : public NodeGraphType::template NodeMap<V>
1031 //This is a must, the constructors need it.
1032 typedef typename NodeGraphType::template NodeMap<V> MapImpl;
1035 NodeMap() : MapImpl() {}
1037 NodeMap(const EdgeSet& graph)
1038 : MapImpl(graph.G) { }
1040 NodeMap(const EdgeSet& graph, const Value& value)
1041 : MapImpl(graph.G, value) { }
1043 NodeMap(const NodeMap& copy)
1044 : MapImpl(static_cast<const MapImpl&>(copy)) {}
1046 template<typename CMap>
1047 NodeMap(const CMap& copy)
1050 NodeMap& operator=(const NodeMap& copy) {
1051 MapImpl::operator=(static_cast<const MapImpl&>(copy));
1055 template <typename CMap>
1056 NodeMap& operator=(const CMap& copy) {
1057 MapImpl::operator=(copy);
1064 template<typename GG>
1065 inline int EdgeSet<GG>::id(Node v) const { return G.id(v); }
1071 #endif //HUGO_LIST_GRAPH_H