alpar@395: // -*- mode:C++ -*- alpar@395: alpar@395: #ifndef HUGO_SMART_GRAPH_H alpar@395: #define HUGO_SMART_GRAPH_H alpar@395: alpar@395: ///\file alpar@397: ///\brief ListGraph and SymListGraph classes. alpar@395: alpar@395: #include alpar@395: #include alpar@395: alpar@395: #include "invalid.h" alpar@395: alpar@395: namespace hugo { alpar@395: alpar@397: class SymListGraph; alpar@395: alpar@395: ///A smart graph class. alpar@395: alpar@397: ///This is a simple and fast erasable graph implementation. alpar@397: /// alpar@395: ///It conforms to the graph interface documented under alpar@395: ///the description of \ref GraphSkeleton. alpar@395: ///\sa \ref GraphSkeleton. alpar@397: class ListGraph { alpar@395: alpar@397: //Nodes are double linked. alpar@397: //The free nodes are only single linked using the "next" field. alpar@395: struct NodeT alpar@395: { alpar@397: int first_in,first_out; alpar@397: int prev, next; alpar@397: // NodeT() {} alpar@395: }; alpar@397: //Edges are double linked. alpar@397: //The free edges are only single linked using the "next_in" field. alpar@395: struct EdgeT alpar@395: { alpar@397: int head, tail; alpar@397: int prev_in, prev_out; alpar@397: int next_in, next_out; alpar@395: //FIXME: is this necessary? alpar@397: // EdgeT() : next_in(-1), next_out(-1) prev_in(-1), prev_out(-1) {} alpar@395: }; alpar@395: alpar@395: std::vector nodes; alpar@397: //The first node alpar@397: int first_node; alpar@397: //The first free node alpar@397: int first_free_node; alpar@395: std::vector edges; alpar@397: //The first free edge alpar@397: int first_free_edge; alpar@395: alpar@397: protected: alpar@395: alpar@395: template class DynMapBase alpar@395: { alpar@395: protected: alpar@397: const ListGraph* G; alpar@395: public: alpar@395: virtual void add(const Key k) = NULL; alpar@395: virtual void erase(const Key k) = NULL; alpar@397: DynMapBase(const ListGraph &_G) : G(&_G) {} alpar@395: virtual ~DynMapBase() {} alpar@397: friend class ListGraph; alpar@395: }; alpar@395: alpar@395: public: alpar@395: template class EdgeMap; alpar@395: template class EdgeMap; alpar@397: alpar@395: class Node; alpar@395: class Edge; alpar@395: alpar@395: // protected: alpar@395: // HELPME: alpar@395: protected: alpar@395: ///\bug It must be public because of SymEdgeMap. alpar@395: /// alpar@395: mutable std::vector * > dyn_node_maps; alpar@395: ///\bug It must be public because of SymEdgeMap. alpar@395: /// alpar@395: mutable std::vector * > dyn_edge_maps; alpar@395: alpar@395: public: alpar@395: alpar@395: class NodeIt; alpar@395: class EdgeIt; alpar@395: class OutEdgeIt; alpar@395: class InEdgeIt; alpar@395: alpar@395: template class NodeMap; alpar@395: template class EdgeMap; alpar@395: alpar@395: public: alpar@395: alpar@397: ListGraph() : nodes(), first_node(-1), alpar@397: first_free_node(-1), edges(), first_free_edge(-1) {} alpar@397: ListGraph(const ListGraph &_g) : nodes(_g.nodes), first_node(_g.first_node), alpar@397: first_free_node(_g.first_free_node), alpar@397: edges(_g.edges), alpar@397: first_free_edge(_g.first_free_edge) {} alpar@395: alpar@397: ~ListGraph() alpar@395: { alpar@395: for(std::vector * >::iterator i=dyn_node_maps.begin(); alpar@395: i!=dyn_node_maps.end(); ++i) (**i).G=NULL; alpar@395: for(std::vector * >::iterator i=dyn_edge_maps.begin(); alpar@395: i!=dyn_edge_maps.end(); ++i) (**i).G=NULL; alpar@395: } alpar@395: alpar@395: int nodeNum() const { return nodes.size(); } //FIXME: What is this? alpar@395: int edgeNum() const { return edges.size(); } //FIXME: What is this? alpar@395: alpar@395: ///\bug This function does something different than alpar@395: ///its name would suggests... alpar@395: int maxNodeId() const { return nodes.size(); } //FIXME: What is this? alpar@395: ///\bug This function does something different than alpar@395: ///its name would suggests... alpar@395: int maxEdgeId() const { return edges.size(); } //FIXME: What is this? alpar@395: alpar@395: Node tail(Edge e) const { return edges[e.n].tail; } alpar@395: Node head(Edge e) const { return edges[e.n].head; } alpar@395: alpar@395: Node aNode(OutEdgeIt e) const { return edges[e.n].tail; } alpar@395: Node aNode(InEdgeIt e) const { return edges[e.n].head; } alpar@395: alpar@395: Node bNode(OutEdgeIt e) const { return edges[e.n].head; } alpar@395: Node bNode(InEdgeIt e) const { return edges[e.n].tail; } alpar@395: alpar@395: NodeIt& first(NodeIt& v) const { alpar@395: v=NodeIt(*this); return v; } alpar@395: EdgeIt& first(EdgeIt& e) const { alpar@395: e=EdgeIt(*this); return e; } alpar@395: OutEdgeIt& first(OutEdgeIt& e, const Node v) const { alpar@395: e=OutEdgeIt(*this,v); return e; } alpar@395: InEdgeIt& first(InEdgeIt& e, const Node v) const { alpar@395: e=InEdgeIt(*this,v); return e; } alpar@395: alpar@395: // template< typename It > alpar@395: // It first() const { It e; first(e); return e; } alpar@395: alpar@395: // template< typename It > alpar@395: // It first(Node v) const { It e; first(e,v); return e; } alpar@395: alpar@395: bool valid(Edge e) const { return e.n!=-1; } alpar@395: bool valid(Node n) const { return n.n!=-1; } alpar@395: alpar@395: void setInvalid(Edge &e) { e.n=-1; } alpar@395: void setInvalid(Node &n) { n.n=-1; } alpar@395: alpar@395: template It getNext(It it) const alpar@395: { It tmp(it); return next(tmp); } alpar@395: alpar@395: NodeIt& next(NodeIt& it) const { alpar@397: it.n=nodes[it.n].next; alpar@395: return it; alpar@395: } alpar@395: OutEdgeIt& next(OutEdgeIt& it) const alpar@395: { it.n=edges[it.n].next_out; return it; } alpar@395: InEdgeIt& next(InEdgeIt& it) const alpar@395: { it.n=edges[it.n].next_in; return it; } alpar@397: EdgeIt& next(EdgeIt& it) const { alpar@397: if(edges[it.n].next_in!=-1) { alpar@397: it.n=edges[it.n].next_in; alpar@397: } alpar@397: else { alpar@397: int n; alpar@397: for(n=nodes[edges[it.n].head].next; alpar@397: n!=-1 && nodes[n].first_in == -1; alpar@397: n = nodes[n].next) ; alpar@397: it.n = (n==-1)?-1:nodes[n].first_in; alpar@397: } alpar@397: return it; alpar@397: } alpar@395: alpar@395: int id(Node v) const { return v.n; } alpar@395: int id(Edge e) const { return e.n; } alpar@395: alpar@397: /// Adds a new node to the graph. alpar@397: alpar@397: /// \todo It adds the nodes in a reversed order. alpar@397: /// (i.e. the lastly added node becomes the first.) alpar@395: Node addNode() { alpar@397: int n; alpar@397: alpar@397: if(first_free_node==-1) alpar@397: { alpar@397: n = nodes.size(); alpar@397: nodes.push_back(NodeT()); alpar@397: } alpar@397: else { alpar@397: n = first_free_node; alpar@397: first_free_node = nodes[n].next; alpar@397: } alpar@397: alpar@397: nodes[n].next = first_node; alpar@397: if(first_node != -1) nodes[first_node].prev = n; alpar@397: first_node = n; alpar@397: nodes[n].prev = -1; alpar@397: alpar@397: nodes[n].first_in = nodes[n].first_out = -1; alpar@397: alpar@397: Node nn; nn.n=n; alpar@395: alpar@397: //Update dynamic maps alpar@395: for(std::vector * >::iterator i=dyn_node_maps.begin(); alpar@397: i!=dyn_node_maps.end(); ++i) (**i).add(nn); alpar@395: alpar@397: return nn; alpar@395: } alpar@395: alpar@395: Edge addEdge(Node u, Node v) { alpar@397: int n; alpar@397: alpar@397: if(first_free_edge==-1) alpar@397: { alpar@397: n = edges.size(); alpar@397: edges.push_back(EdgeT()); alpar@397: } alpar@397: else { alpar@397: n = first_free_edge; alpar@397: first_free_edge = edges[n].next_in; alpar@397: } alpar@397: alpar@397: edges[n].tail = u.n; edges[n].head = v.n; alpar@395: alpar@397: edges[n].next_out = nodes[u.n].first_out; alpar@397: if(nodes[u.n].first_out != -1) edges[nodes[u.n].first_out].prev_out = n; alpar@397: edges[n].next_in = nodes[v.n].first_in; alpar@397: if(nodes[v.n].first_in != -1) edges[nodes[v.n].first_in].prev_in = n; alpar@397: edges[n].prev_in = edges[n].prev_out = -1; alpar@397: alpar@397: nodes[u.n].first_out = nodes[v.n].first_in = n; alpar@397: alpar@397: Edge e; e.n=n; alpar@397: alpar@397: //Update dynamic maps alpar@395: for(std::vector * >::iterator i=dyn_edge_maps.begin(); alpar@395: i!=dyn_edge_maps.end(); ++i) (**i).add(e); alpar@395: alpar@395: return e; alpar@395: } alpar@395: alpar@397: private: alpar@397: void eraseEdge(int n) { alpar@397: alpar@397: if(edges[n].next_in!=-1) alpar@397: edges[edges[n].next_in].prev_in = edges[n].prev_in; alpar@397: if(edges[n].prev_in!=-1) alpar@397: edges[edges[n].prev_in].next_in = edges[n].next_in; alpar@397: else nodes[edges[n].head].first_in = edges[n].next_in; alpar@397: alpar@397: if(edges[n].next_out!=-1) alpar@397: edges[edges[n].next_out].prev_out = edges[n].prev_out; alpar@397: if(edges[n].prev_out!=-1) alpar@397: edges[edges[n].prev_out].next_out = edges[n].next_out; alpar@397: else nodes[edges[n].tail].first_out = edges[n].next_out; alpar@397: alpar@397: edges[n].next_in = first_free_edge; alpar@397: first_free_edge = -1; alpar@397: alpar@397: //Update dynamic maps alpar@397: Edge e; e.n=n; alpar@397: for(std::vector * >::iterator i=dyn_edge_maps.begin(); alpar@397: i!=dyn_edge_maps.end(); ++i) (**i).erase(e); alpar@397: } alpar@397: alpar@397: public: alpar@397: alpar@397: void erase(Node nn) { alpar@397: int n=nn.n; alpar@397: alpar@397: int m; alpar@397: while((m=nodes[n].first_in)!=-1) eraseEdge(m); alpar@397: while((m=nodes[n].first_out)!=-1) eraseEdge(m); alpar@397: alpar@397: if(nodes[n].next != -1) nodes[nodes[n].next].prev = nodes[n].prev; alpar@397: if(nodes[n].prev != -1) nodes[nodes[n].prev].next = nodes[n].next; alpar@397: else first_node = nodes[n].next; alpar@397: alpar@397: nodes[n].next = first_free_node; alpar@397: first_free_node = n; alpar@397: alpar@397: //Update dynamic maps alpar@397: for(std::vector * >::iterator i=dyn_node_maps.begin(); alpar@397: i!=dyn_node_maps.end(); ++i) (**i).erase(nn); alpar@397: } alpar@397: alpar@397: void erase(Edge e) { eraseEdge(e.n); } alpar@397: alpar@397: ///\bug Dynamic maps must be updated! alpar@397: /// alpar@397: void clear() { alpar@397: nodes.clear();edges.clear(); alpar@397: first_node=first_free_node=first_free_edge=-1; alpar@397: } alpar@395: alpar@395: class Node { alpar@397: friend class ListGraph; alpar@395: template friend class NodeMap; alpar@395: alpar@395: friend class Edge; alpar@395: friend class OutEdgeIt; alpar@395: friend class InEdgeIt; alpar@395: friend class SymEdge; alpar@395: alpar@395: protected: alpar@395: int n; alpar@397: friend int ListGraph::id(Node v) const; alpar@395: Node(int nn) {n=nn;} alpar@395: public: alpar@395: Node() {} alpar@395: Node (Invalid i) { n=-1; } alpar@395: bool operator==(const Node i) const {return n==i.n;} alpar@395: bool operator!=(const Node i) const {return n!=i.n;} alpar@395: bool operator<(const Node i) const {return n friend class EdgeMap; alpar@395: alpar@397: //template friend class SymListGraph::SymEdgeMap; alpar@397: //friend Edge SymListGraph::opposite(Edge) const; alpar@395: alpar@395: friend class Node; alpar@395: friend class NodeIt; alpar@395: protected: alpar@395: int n; alpar@397: friend int ListGraph::id(Edge e) const; alpar@395: alpar@395: Edge(int nn) {n=nn;} alpar@395: public: alpar@395: Edge() { } alpar@395: Edge (Invalid) { n=-1; } alpar@395: bool operator==(const Edge i) const {return n==i.n;} alpar@395: bool operator!=(const Edge i) const {return n!=i.n;} alpar@395: bool operator<(const Edge i) const {return n class NodeMap : public DynMapBase alpar@395: { alpar@395: std::vector container; alpar@395: alpar@395: public: alpar@395: typedef T ValueType; alpar@395: typedef Node KeyType; alpar@395: alpar@397: NodeMap(const ListGraph &_G) : alpar@395: DynMapBase(_G), container(_G.maxNodeId()) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: } alpar@397: NodeMap(const ListGraph &_G,const T &t) : alpar@395: DynMapBase(_G), container(_G.maxNodeId(),t) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: } alpar@395: alpar@395: NodeMap(const NodeMap &m) : alpar@395: DynMapBase(*m.G), container(m.container) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: } alpar@395: alpar@395: template friend class NodeMap; alpar@395: alpar@395: ///\todo It can copy between different types. alpar@395: /// alpar@395: template NodeMap(const NodeMap &m) : alpar@395: DynMapBase(*m.G) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: typename std::vector::const_iterator i; alpar@395: for(typename std::vector::const_iterator i=m.container.begin(); alpar@395: i!=m.container.end(); alpar@395: i++) alpar@395: container.push_back(*i); alpar@395: } alpar@395: ~NodeMap() alpar@395: { alpar@395: if(G) { alpar@395: std::vector* >::iterator i; alpar@395: for(i=G->dyn_node_maps.begin(); alpar@395: i!=G->dyn_node_maps.end() && *i!=this; ++i) ; alpar@395: //if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow... alpar@395: //A better way to do that: (Is this really important?) alpar@395: if(*i==this) { alpar@395: *i=G->dyn_node_maps.back(); alpar@395: G->dyn_node_maps.pop_back(); alpar@395: } alpar@395: } alpar@395: } alpar@395: alpar@395: void add(const Node k) alpar@395: { alpar@395: if(k.n>=int(container.size())) container.resize(k.n+1); alpar@395: } alpar@395: alpar@395: void erase(const Node) { } alpar@395: alpar@395: void set(Node n, T a) { container[n.n]=a; } alpar@395: //'T& operator[](Node n)' would be wrong here alpar@395: typename std::vector::reference alpar@395: operator[](Node n) { return container[n.n]; } alpar@395: //'const T& operator[](Node n)' would be wrong here alpar@395: typename std::vector::const_reference alpar@395: operator[](Node n) const { return container[n.n]; } alpar@395: alpar@395: ///\warning There is no safety check at all! alpar@395: ///Using operator = between maps attached to different graph may alpar@395: ///cause serious problem. alpar@395: ///\todo Is this really so? alpar@395: ///\todo It can copy between different types. alpar@395: const NodeMap& operator=(const NodeMap &m) alpar@395: { alpar@395: container = m.container; alpar@395: return *this; alpar@395: } alpar@395: template alpar@395: const NodeMap& operator=(const NodeMap &m) alpar@395: { alpar@395: copy(m.container.begin(), m.container.end(), container.begin()); alpar@395: return *this; alpar@395: } alpar@395: alpar@395: void update() {} //Useless for Dynamic Maps alpar@395: void update(T a) {} //Useless for Dynamic Maps alpar@395: }; alpar@395: alpar@395: template class EdgeMap : public DynMapBase alpar@395: { alpar@395: std::vector container; alpar@395: alpar@395: public: alpar@395: typedef T ValueType; alpar@395: typedef Edge KeyType; alpar@395: alpar@397: EdgeMap(const ListGraph &_G) : alpar@395: DynMapBase(_G), container(_G.maxEdgeId()) alpar@395: { alpar@395: //FIXME: What if there are empty Id's? alpar@395: //FIXME: Can I use 'this' in a constructor? alpar@395: G->dyn_edge_maps.push_back(this); alpar@395: } alpar@397: EdgeMap(const ListGraph &_G,const T &t) : alpar@395: DynMapBase(_G), container(_G.maxEdgeId(),t) alpar@395: { alpar@395: G->dyn_edge_maps.push_back(this); alpar@395: } alpar@395: EdgeMap(const EdgeMap &m) : alpar@395: DynMapBase(*m.G), container(m.container) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: } alpar@395: alpar@395: template friend class EdgeMap; alpar@395: alpar@395: ///\todo It can copy between different types. alpar@395: /// alpar@395: template EdgeMap(const EdgeMap &m) : alpar@395: DynMapBase(*m.G) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: typename std::vector::const_iterator i; alpar@395: for(typename std::vector::const_iterator i=m.container.begin(); alpar@395: i!=m.container.end(); alpar@395: i++) alpar@395: container.push_back(*i); alpar@395: } alpar@395: ~EdgeMap() alpar@395: { alpar@395: if(G) { alpar@395: std::vector* >::iterator i; alpar@395: for(i=G->dyn_edge_maps.begin(); alpar@395: i!=G->dyn_edge_maps.end() && *i!=this; ++i) ; alpar@395: //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow... alpar@395: //A better way to do that: (Is this really important?) alpar@395: if(*i==this) { alpar@395: *i=G->dyn_edge_maps.back(); alpar@395: G->dyn_edge_maps.pop_back(); alpar@395: } alpar@395: } alpar@395: } alpar@395: alpar@395: void add(const Edge k) alpar@395: { alpar@395: if(k.n>=int(container.size())) container.resize(k.n+1); alpar@395: } alpar@395: void erase(const Edge) { } alpar@395: alpar@395: void set(Edge n, T a) { container[n.n]=a; } alpar@395: //T get(Edge n) const { return container[n.n]; } alpar@395: typename std::vector::reference alpar@395: operator[](Edge n) { return container[n.n]; } alpar@395: typename std::vector::const_reference alpar@395: operator[](Edge n) const { return container[n.n]; } alpar@395: alpar@395: ///\warning There is no safety check at all! alpar@395: ///Using operator = between maps attached to different graph may alpar@395: ///cause serious problem. alpar@395: ///\todo Is this really so? alpar@395: ///\todo It can copy between different types. alpar@395: const EdgeMap& operator=(const EdgeMap &m) alpar@395: { alpar@395: container = m.container; alpar@395: return *this; alpar@395: } alpar@395: template alpar@395: const EdgeMap& operator=(const EdgeMap &m) alpar@395: { alpar@395: copy(m.container.begin(), m.container.end(), container.begin()); alpar@395: return *this; alpar@395: } alpar@395: alpar@395: void update() {} //Useless for DynMaps alpar@395: void update(T a) {} //Useless for DynMaps alpar@395: }; alpar@395: alpar@395: }; alpar@395: alpar@395: ///Graph for bidirectional edges. alpar@395: alpar@395: ///The purpose of this graph structure is to handle graphs alpar@395: ///having bidirectional edges. Here the function \c addEdge(u,v) adds a pair alpar@395: ///of oppositely directed edges. alpar@395: ///There is a new edge map type called alpar@397: ///\ref SymListGraph::SymEdgeMap "SymEdgeMap" alpar@395: ///that complements this alpar@395: ///feature by alpar@395: ///storing shared values for the edge pairs. The usual alpar@395: ///\ref GraphSkeleton::EdgeMap "EdgeMap" alpar@395: ///can be used alpar@395: ///as well. alpar@395: /// alpar@395: ///The oppositely directed edge can also be obtained easily alpar@395: ///using \ref opposite. alpar@397: /// alpar@397: ///Here erase(Edge) deletes a pair of edges. alpar@397: /// alpar@397: ///\todo this date structure need some reconsiderations. Maybe it alpar@397: ///should be implemented independently from ListGraph. alpar@395: alpar@397: class SymListGraph : public ListGraph alpar@395: { alpar@395: public: alpar@395: template class SymEdgeMap; alpar@395: template friend class SymEdgeMap; alpar@395: alpar@397: SymListGraph() : ListGraph() { } alpar@397: SymListGraph(const ListGraph &_g) : ListGraph(_g) { } alpar@397: ///Adds a pair of oppositely directed edges to the graph. alpar@395: Edge addEdge(Node u, Node v) alpar@395: { alpar@397: Edge e = ListGraph::addEdge(u,v); alpar@397: ListGraph::addEdge(v,u); alpar@395: return e; alpar@395: } alpar@395: alpar@397: void erase(Node n) { ListGraph::erase(n); } alpar@395: ///The oppositely directed edge. alpar@395: alpar@395: ///Returns the oppositely directed alpar@395: ///pair of the edge \c e. alpar@395: Edge opposite(Edge e) const alpar@395: { alpar@395: Edge f; alpar@395: f.idref() = e.idref() - 2*(e.idref()%2) + 1; alpar@395: return f; alpar@395: } alpar@395: alpar@397: ///Removes a pair of oppositely directed edges to the graph. alpar@397: void erase(Edge e) { alpar@397: ListGraph::erase(opposite(e)); alpar@397: ListGraph::erase(e); alpar@397: } alpar@397: alpar@395: ///Common data storage for the edge pairs. alpar@395: alpar@395: ///This map makes it possible to store data shared by the oppositely alpar@395: ///directed pairs of edges. alpar@395: template class SymEdgeMap : public DynMapBase alpar@395: { alpar@395: std::vector container; alpar@395: alpar@395: public: alpar@395: typedef T ValueType; alpar@395: typedef Edge KeyType; alpar@395: alpar@397: SymEdgeMap(const SymListGraph &_G) : alpar@395: DynMapBase(_G), container(_G.maxEdgeId()/2) alpar@395: { alpar@397: static_cast(G)->dyn_edge_maps.push_back(this); alpar@395: } alpar@397: SymEdgeMap(const SymListGraph &_G,const T &t) : alpar@395: DynMapBase(_G), container(_G.maxEdgeId()/2,t) alpar@395: { alpar@395: G->dyn_edge_maps.push_back(this); alpar@395: } alpar@395: alpar@395: SymEdgeMap(const SymEdgeMap &m) : alpar@395: DynMapBase(*m.G), container(m.container) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: } alpar@395: alpar@395: // template friend class SymEdgeMap; alpar@395: alpar@395: ///\todo It can copy between different types. alpar@395: /// alpar@395: alpar@395: template SymEdgeMap(const SymEdgeMap &m) : alpar@395: DynMapBase(*m.G) alpar@395: { alpar@395: G->dyn_node_maps.push_back(this); alpar@395: typename std::vector::const_iterator i; alpar@395: for(typename std::vector::const_iterator i=m.container.begin(); alpar@395: i!=m.container.end(); alpar@395: i++) alpar@395: container.push_back(*i); alpar@395: } alpar@395: alpar@395: ~SymEdgeMap() alpar@395: { alpar@395: if(G) { alpar@395: std::vector* >::iterator i; alpar@397: for(i=static_cast(G)->dyn_edge_maps.begin(); alpar@397: i!=static_cast(G)->dyn_edge_maps.end() alpar@395: && *i!=this; ++i) ; alpar@395: //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow... alpar@395: //A better way to do that: (Is this really important?) alpar@395: if(*i==this) { alpar@397: *i=static_cast(G)->dyn_edge_maps.back(); alpar@397: static_cast(G)->dyn_edge_maps.pop_back(); alpar@395: } alpar@395: } alpar@395: } alpar@395: alpar@395: void add(const Edge k) alpar@395: { alpar@395: if(!k.idref()%2&&k.idref()/2>=int(container.size())) alpar@395: container.resize(k.idref()/2+1); alpar@395: } alpar@395: void erase(const Edge k) { } alpar@395: alpar@395: void set(Edge n, T a) { container[n.idref()/2]=a; } alpar@395: //T get(Edge n) const { return container[n.idref()/2]; } alpar@395: typename std::vector::reference alpar@395: operator[](Edge n) { return container[n.idref()/2]; } alpar@395: typename std::vector::const_reference alpar@395: operator[](Edge n) const { return container[n.idref()/2]; } alpar@395: alpar@395: ///\warning There is no safety check at all! alpar@395: ///Using operator = between maps attached to different graph may alpar@395: ///cause serious problem. alpar@395: ///\todo Is this really so? alpar@395: ///\todo It can copy between different types. alpar@395: const SymEdgeMap& operator=(const SymEdgeMap &m) alpar@395: { alpar@395: container = m.container; alpar@395: return *this; alpar@395: } alpar@395: template alpar@395: const SymEdgeMap& operator=(const SymEdgeMap &m) alpar@395: { alpar@395: copy(m.container.begin(), m.container.end(), container.begin()); alpar@395: return *this; alpar@395: } alpar@395: alpar@395: void update() {} //Useless for DynMaps alpar@395: void update(T a) {} //Useless for DynMaps alpar@395: alpar@395: }; alpar@395: alpar@395: }; alpar@395: alpar@395: alpar@395: } //namespace hugo alpar@395: alpar@395: alpar@395: alpar@395: alpar@395: #endif //SMART_GRAPH_H