0
2
0
| ... | ... |
@@ -797,97 +797,99 @@ |
| 797 | 797 |
int first_free_arc; |
| 798 | 798 |
|
| 799 | 799 |
public: |
| 800 | 800 |
|
| 801 | 801 |
typedef ListGraphBase Digraph; |
| 802 | 802 |
|
| 803 | 803 |
class Node; |
| 804 | 804 |
class Arc; |
| 805 | 805 |
class Edge; |
| 806 | 806 |
|
| 807 | 807 |
class Node {
|
| 808 | 808 |
friend class ListGraphBase; |
| 809 | 809 |
protected: |
| 810 | 810 |
|
| 811 | 811 |
int id; |
| 812 | 812 |
explicit Node(int pid) { id = pid;}
|
| 813 | 813 |
|
| 814 | 814 |
public: |
| 815 | 815 |
Node() {}
|
| 816 | 816 |
Node (Invalid) { id = -1; }
|
| 817 | 817 |
bool operator==(const Node& node) const {return id == node.id;}
|
| 818 | 818 |
bool operator!=(const Node& node) const {return id != node.id;}
|
| 819 | 819 |
bool operator<(const Node& node) const {return id < node.id;}
|
| 820 | 820 |
}; |
| 821 | 821 |
|
| 822 | 822 |
class Edge {
|
| 823 | 823 |
friend class ListGraphBase; |
| 824 | 824 |
protected: |
| 825 | 825 |
|
| 826 | 826 |
int id; |
| 827 | 827 |
explicit Edge(int pid) { id = pid;}
|
| 828 | 828 |
|
| 829 | 829 |
public: |
| 830 | 830 |
Edge() {}
|
| 831 | 831 |
Edge (Invalid) { id = -1; }
|
| 832 | 832 |
bool operator==(const Edge& edge) const {return id == edge.id;}
|
| 833 | 833 |
bool operator!=(const Edge& edge) const {return id != edge.id;}
|
| 834 | 834 |
bool operator<(const Edge& edge) const {return id < edge.id;}
|
| 835 | 835 |
}; |
| 836 | 836 |
|
| 837 | 837 |
class Arc {
|
| 838 | 838 |
friend class ListGraphBase; |
| 839 | 839 |
protected: |
| 840 | 840 |
|
| 841 | 841 |
int id; |
| 842 | 842 |
explicit Arc(int pid) { id = pid;}
|
| 843 | 843 |
|
| 844 | 844 |
public: |
| 845 |
operator Edge() const {
|
|
| 845 |
operator Edge() const {
|
|
| 846 |
return id != -1 ? edgeFromId(id / 2) : INVALID; |
|
| 847 |
} |
|
| 846 | 848 |
|
| 847 | 849 |
Arc() {}
|
| 848 | 850 |
Arc (Invalid) { id = -1; }
|
| 849 | 851 |
bool operator==(const Arc& arc) const {return id == arc.id;}
|
| 850 | 852 |
bool operator!=(const Arc& arc) const {return id != arc.id;}
|
| 851 | 853 |
bool operator<(const Arc& arc) const {return id < arc.id;}
|
| 852 | 854 |
}; |
| 853 | 855 |
|
| 854 | 856 |
|
| 855 | 857 |
|
| 856 | 858 |
ListGraphBase() |
| 857 | 859 |
: nodes(), first_node(-1), |
| 858 | 860 |
first_free_node(-1), arcs(), first_free_arc(-1) {}
|
| 859 | 861 |
|
| 860 | 862 |
|
| 861 | 863 |
int maxNodeId() const { return nodes.size()-1; }
|
| 862 | 864 |
int maxEdgeId() const { return arcs.size() / 2 - 1; }
|
| 863 | 865 |
int maxArcId() const { return arcs.size()-1; }
|
| 864 | 866 |
|
| 865 | 867 |
Node source(Arc e) const { return Node(arcs[e.id ^ 1].target); }
|
| 866 | 868 |
Node target(Arc e) const { return Node(arcs[e.id].target); }
|
| 867 | 869 |
|
| 868 | 870 |
Node u(Edge e) const { return Node(arcs[2 * e.id].target); }
|
| 869 | 871 |
Node v(Edge e) const { return Node(arcs[2 * e.id + 1].target); }
|
| 870 | 872 |
|
| 871 | 873 |
static bool direction(Arc e) {
|
| 872 | 874 |
return (e.id & 1) == 1; |
| 873 | 875 |
} |
| 874 | 876 |
|
| 875 | 877 |
static Arc direct(Edge e, bool d) {
|
| 876 | 878 |
return Arc(e.id * 2 + (d ? 1 : 0)); |
| 877 | 879 |
} |
| 878 | 880 |
|
| 879 | 881 |
void first(Node& node) const {
|
| 880 | 882 |
node.id = first_node; |
| 881 | 883 |
} |
| 882 | 884 |
|
| 883 | 885 |
void next(Node& node) const {
|
| 884 | 886 |
node.id = nodes[node.id].next; |
| 885 | 887 |
} |
| 886 | 888 |
|
| 887 | 889 |
void first(Arc& e) const {
|
| 888 | 890 |
int n = first_node; |
| 889 | 891 |
while (n != -1 && nodes[n].first_out == -1) {
|
| 890 | 892 |
n = nodes[n].next; |
| 891 | 893 |
} |
| 892 | 894 |
e.id = (n == -1) ? -1 : nodes[n].first_out; |
| 893 | 895 |
} |
| ... | ... |
@@ -420,97 +420,99 @@ |
| 420 | 420 |
int first_free_arc; |
| 421 | 421 |
|
| 422 | 422 |
public: |
| 423 | 423 |
|
| 424 | 424 |
typedef SmartGraphBase Digraph; |
| 425 | 425 |
|
| 426 | 426 |
class Node; |
| 427 | 427 |
class Arc; |
| 428 | 428 |
class Edge; |
| 429 | 429 |
|
| 430 | 430 |
class Node {
|
| 431 | 431 |
friend class SmartGraphBase; |
| 432 | 432 |
protected: |
| 433 | 433 |
|
| 434 | 434 |
int _id; |
| 435 | 435 |
explicit Node(int id) { _id = id;}
|
| 436 | 436 |
|
| 437 | 437 |
public: |
| 438 | 438 |
Node() {}
|
| 439 | 439 |
Node (Invalid) { _id = -1; }
|
| 440 | 440 |
bool operator==(const Node& node) const {return _id == node._id;}
|
| 441 | 441 |
bool operator!=(const Node& node) const {return _id != node._id;}
|
| 442 | 442 |
bool operator<(const Node& node) const {return _id < node._id;}
|
| 443 | 443 |
}; |
| 444 | 444 |
|
| 445 | 445 |
class Edge {
|
| 446 | 446 |
friend class SmartGraphBase; |
| 447 | 447 |
protected: |
| 448 | 448 |
|
| 449 | 449 |
int _id; |
| 450 | 450 |
explicit Edge(int id) { _id = id;}
|
| 451 | 451 |
|
| 452 | 452 |
public: |
| 453 | 453 |
Edge() {}
|
| 454 | 454 |
Edge (Invalid) { _id = -1; }
|
| 455 | 455 |
bool operator==(const Edge& arc) const {return _id == arc._id;}
|
| 456 | 456 |
bool operator!=(const Edge& arc) const {return _id != arc._id;}
|
| 457 | 457 |
bool operator<(const Edge& arc) const {return _id < arc._id;}
|
| 458 | 458 |
}; |
| 459 | 459 |
|
| 460 | 460 |
class Arc {
|
| 461 | 461 |
friend class SmartGraphBase; |
| 462 | 462 |
protected: |
| 463 | 463 |
|
| 464 | 464 |
int _id; |
| 465 | 465 |
explicit Arc(int id) { _id = id;}
|
| 466 | 466 |
|
| 467 | 467 |
public: |
| 468 |
operator Edge() const {
|
|
| 468 |
operator Edge() const {
|
|
| 469 |
return _id != -1 ? edgeFromId(_id / 2) : INVALID; |
|
| 470 |
} |
|
| 469 | 471 |
|
| 470 | 472 |
Arc() {}
|
| 471 | 473 |
Arc (Invalid) { _id = -1; }
|
| 472 | 474 |
bool operator==(const Arc& arc) const {return _id == arc._id;}
|
| 473 | 475 |
bool operator!=(const Arc& arc) const {return _id != arc._id;}
|
| 474 | 476 |
bool operator<(const Arc& arc) const {return _id < arc._id;}
|
| 475 | 477 |
}; |
| 476 | 478 |
|
| 477 | 479 |
|
| 478 | 480 |
|
| 479 | 481 |
SmartGraphBase() |
| 480 | 482 |
: nodes(), arcs() {}
|
| 481 | 483 |
|
| 482 | 484 |
|
| 483 | 485 |
int maxNodeId() const { return nodes.size()-1; }
|
| 484 | 486 |
int maxEdgeId() const { return arcs.size() / 2 - 1; }
|
| 485 | 487 |
int maxArcId() const { return arcs.size()-1; }
|
| 486 | 488 |
|
| 487 | 489 |
Node source(Arc e) const { return Node(arcs[e._id ^ 1].target); }
|
| 488 | 490 |
Node target(Arc e) const { return Node(arcs[e._id].target); }
|
| 489 | 491 |
|
| 490 | 492 |
Node u(Edge e) const { return Node(arcs[2 * e._id].target); }
|
| 491 | 493 |
Node v(Edge e) const { return Node(arcs[2 * e._id + 1].target); }
|
| 492 | 494 |
|
| 493 | 495 |
static bool direction(Arc e) {
|
| 494 | 496 |
return (e._id & 1) == 1; |
| 495 | 497 |
} |
| 496 | 498 |
|
| 497 | 499 |
static Arc direct(Edge e, bool d) {
|
| 498 | 500 |
return Arc(e._id * 2 + (d ? 1 : 0)); |
| 499 | 501 |
} |
| 500 | 502 |
|
| 501 | 503 |
void first(Node& node) const {
|
| 502 | 504 |
node._id = nodes.size() - 1; |
| 503 | 505 |
} |
| 504 | 506 |
|
| 505 | 507 |
void next(Node& node) const {
|
| 506 | 508 |
--node._id; |
| 507 | 509 |
} |
| 508 | 510 |
|
| 509 | 511 |
void first(Arc& arc) const {
|
| 510 | 512 |
arc._id = arcs.size() - 1; |
| 511 | 513 |
} |
| 512 | 514 |
|
| 513 | 515 |
void next(Arc& arc) const {
|
| 514 | 516 |
--arc._id; |
| 515 | 517 |
} |
| 516 | 518 |
|
0 comments (0 inline)