113 static int id(Arc a) { return a._id; } |
113 static int id(Arc a) { return a._id; } |
114 |
114 |
115 static Node nodeFromId(int id) { return Node(id);} |
115 static Node nodeFromId(int id) { return Node(id);} |
116 static Arc arcFromId(int id) { return Arc(id);} |
116 static Arc arcFromId(int id) { return Arc(id);} |
117 |
117 |
|
118 bool valid(Node n) const { |
|
119 return n._id >= 0 && n._id < static_cast<int>(nodes.size()); |
|
120 } |
|
121 bool valid(Arc a) const { |
|
122 return a._id >= 0 && a._id < static_cast<int>(arcs.size()); |
|
123 } |
|
124 |
118 class Node { |
125 class Node { |
119 friend class SmartDigraphBase; |
126 friend class SmartDigraphBase; |
120 friend class SmartDigraph; |
127 friend class SmartDigraph; |
121 |
128 |
122 protected: |
129 protected: |
258 /// be very large (e.g. it will contain millions of nodes and/or arcs) |
265 /// be very large (e.g. it will contain millions of nodes and/or arcs) |
259 /// then it is worth reserving space for this amount before starting |
266 /// then it is worth reserving space for this amount before starting |
260 /// to build the digraph. |
267 /// to build the digraph. |
261 /// \sa reserveNode |
268 /// \sa reserveNode |
262 void reserveArc(int m) { arcs.reserve(m); }; |
269 void reserveArc(int m) { arcs.reserve(m); }; |
|
270 |
|
271 /// \brief Node validity check |
|
272 /// |
|
273 /// This function gives back true if the given node is valid, |
|
274 /// ie. it is a real node of the graph. |
|
275 /// |
|
276 /// \warning A removed node (using Snapshot) could become valid again |
|
277 /// when new nodes are added to the graph. |
|
278 bool valid(Node n) const { return Parent::valid(n); } |
|
279 |
|
280 /// \brief Arc validity check |
|
281 /// |
|
282 /// This function gives back true if the given arc is valid, |
|
283 /// ie. it is a real arc of the graph. |
|
284 /// |
|
285 /// \warning A removed arc (using Snapshot) could become valid again |
|
286 /// when new arcs are added to the graph. |
|
287 bool valid(Arc a) const { return Parent::valid(a); } |
263 |
288 |
264 ///Clear the digraph. |
289 ///Clear the digraph. |
265 |
290 |
266 ///Erase all the nodes and arcs from the digraph. |
291 ///Erase all the nodes and arcs from the digraph. |
267 /// |
292 /// |
548 |
573 |
549 static Node nodeFromId(int id) { return Node(id);} |
574 static Node nodeFromId(int id) { return Node(id);} |
550 static Arc arcFromId(int id) { return Arc(id);} |
575 static Arc arcFromId(int id) { return Arc(id);} |
551 static Edge edgeFromId(int id) { return Edge(id);} |
576 static Edge edgeFromId(int id) { return Edge(id);} |
552 |
577 |
|
578 bool valid(Node n) const { |
|
579 return n._id >= 0 && n._id < static_cast<int>(nodes.size()); |
|
580 } |
|
581 bool valid(Arc a) const { |
|
582 return a._id >= 0 && a._id < static_cast<int>(arcs.size()); |
|
583 } |
|
584 bool valid(Edge e) const { |
|
585 return e._id >= 0 && 2 * e._id < static_cast<int>(arcs.size()); |
|
586 } |
|
587 |
553 Node addNode() { |
588 Node addNode() { |
554 int n = nodes.size(); |
589 int n = nodes.size(); |
555 nodes.push_back(NodeT()); |
590 nodes.push_back(NodeT()); |
556 nodes[n].first_out = -1; |
591 nodes[n].first_out = -1; |
557 |
592 |
639 ///and \c t. |
674 ///and \c t. |
640 ///\return the new edge. |
675 ///\return the new edge. |
641 Edge addEdge(const Node& s, const Node& t) { |
676 Edge addEdge(const Node& s, const Node& t) { |
642 return Parent::addEdge(s, t); |
677 return Parent::addEdge(s, t); |
643 } |
678 } |
|
679 |
|
680 /// \brief Node validity check |
|
681 /// |
|
682 /// This function gives back true if the given node is valid, |
|
683 /// ie. it is a real node of the graph. |
|
684 /// |
|
685 /// \warning A removed node (using Snapshot) could become valid again |
|
686 /// when new nodes are added to the graph. |
|
687 bool valid(Node n) const { return Parent::valid(n); } |
|
688 |
|
689 /// \brief Arc validity check |
|
690 /// |
|
691 /// This function gives back true if the given arc is valid, |
|
692 /// ie. it is a real arc of the graph. |
|
693 /// |
|
694 /// \warning A removed arc (using Snapshot) could become valid again |
|
695 /// when new edges are added to the graph. |
|
696 bool valid(Arc a) const { return Parent::valid(a); } |
|
697 |
|
698 /// \brief Edge validity check |
|
699 /// |
|
700 /// This function gives back true if the given edge is valid, |
|
701 /// ie. it is a real edge of the graph. |
|
702 /// |
|
703 /// \warning A removed edge (using Snapshot) could become valid again |
|
704 /// when new edges are added to the graph. |
|
705 bool valid(Edge e) const { return Parent::valid(e); } |
644 |
706 |
645 ///Clear the graph. |
707 ///Clear the graph. |
646 |
708 |
647 ///Erase all the nodes and edges from the graph. |
709 ///Erase all the nodes and edges from the graph. |
648 /// |
710 /// |