| ... | ... |
@@ -71,110 +71,110 @@ |
| 71 | 71 |
Node() {}
|
| 72 | 72 |
Node (Invalid) { id = -1; }
|
| 73 | 73 |
bool operator==(const Node& node) const {return id == node.id;}
|
| 74 | 74 |
bool operator!=(const Node& node) const {return id != node.id;}
|
| 75 | 75 |
bool operator<(const Node& node) const {return id < node.id;}
|
| 76 | 76 |
}; |
| 77 | 77 |
|
| 78 | 78 |
class Arc {
|
| 79 | 79 |
friend class ListDigraphBase; |
| 80 | 80 |
protected: |
| 81 | 81 |
|
| 82 | 82 |
int id; |
| 83 | 83 |
explicit Arc(int pid) { id = pid;}
|
| 84 | 84 |
|
| 85 | 85 |
public: |
| 86 | 86 |
Arc() {}
|
| 87 | 87 |
Arc (Invalid) { id = -1; }
|
| 88 | 88 |
bool operator==(const Arc& arc) const {return id == arc.id;}
|
| 89 | 89 |
bool operator!=(const Arc& arc) const {return id != arc.id;}
|
| 90 | 90 |
bool operator<(const Arc& arc) const {return id < arc.id;}
|
| 91 | 91 |
}; |
| 92 | 92 |
|
| 93 | 93 |
|
| 94 | 94 |
|
| 95 | 95 |
ListDigraphBase() |
| 96 | 96 |
: nodes(), first_node(-1), |
| 97 | 97 |
first_free_node(-1), arcs(), first_free_arc(-1) {}
|
| 98 | 98 |
|
| 99 | 99 |
|
| 100 | 100 |
int maxNodeId() const { return nodes.size()-1; }
|
| 101 | 101 |
int maxArcId() const { return arcs.size()-1; }
|
| 102 | 102 |
|
| 103 | 103 |
Node source(Arc e) const { return Node(arcs[e.id].source); }
|
| 104 | 104 |
Node target(Arc e) const { return Node(arcs[e.id].target); }
|
| 105 | 105 |
|
| 106 | 106 |
|
| 107 | 107 |
void first(Node& node) const {
|
| 108 | 108 |
node.id = first_node; |
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 | 111 |
void next(Node& node) const {
|
| 112 | 112 |
node.id = nodes[node.id].next; |
| 113 | 113 |
} |
| 114 | 114 |
|
| 115 | 115 |
|
| 116 | 116 |
void first(Arc& arc) const {
|
| 117 | 117 |
int n; |
| 118 | 118 |
for(n = first_node; |
| 119 |
n!=-1 && nodes[n]. |
|
| 119 |
n != -1 && nodes[n].first_out == -1; |
|
| 120 | 120 |
n = nodes[n].next) {}
|
| 121 |
arc.id = (n == -1) ? -1 : nodes[n]. |
|
| 121 |
arc.id = (n == -1) ? -1 : nodes[n].first_out; |
|
| 122 | 122 |
} |
| 123 | 123 |
|
| 124 | 124 |
void next(Arc& arc) const {
|
| 125 |
if (arcs[arc.id].next_in != -1) {
|
|
| 126 |
arc.id = arcs[arc.id].next_in; |
|
| 125 |
if (arcs[arc.id].next_out != -1) {
|
|
| 126 |
arc.id = arcs[arc.id].next_out; |
|
| 127 | 127 |
} else {
|
| 128 | 128 |
int n; |
| 129 |
for(n = nodes[arcs[arc.id].target].next; |
|
| 130 |
n!=-1 && nodes[n].first_in == -1; |
|
| 129 |
for(n = nodes[arcs[arc.id].source].next; |
|
| 130 |
n != -1 && nodes[n].first_out == -1; |
|
| 131 | 131 |
n = nodes[n].next) {}
|
| 132 |
arc.id = (n == -1) ? -1 : nodes[n]. |
|
| 132 |
arc.id = (n == -1) ? -1 : nodes[n].first_out; |
|
| 133 | 133 |
} |
| 134 | 134 |
} |
| 135 | 135 |
|
| 136 | 136 |
void firstOut(Arc &e, const Node& v) const {
|
| 137 | 137 |
e.id = nodes[v.id].first_out; |
| 138 | 138 |
} |
| 139 | 139 |
void nextOut(Arc &e) const {
|
| 140 | 140 |
e.id=arcs[e.id].next_out; |
| 141 | 141 |
} |
| 142 | 142 |
|
| 143 | 143 |
void firstIn(Arc &e, const Node& v) const {
|
| 144 | 144 |
e.id = nodes[v.id].first_in; |
| 145 | 145 |
} |
| 146 | 146 |
void nextIn(Arc &e) const {
|
| 147 | 147 |
e.id=arcs[e.id].next_in; |
| 148 | 148 |
} |
| 149 | 149 |
|
| 150 | 150 |
|
| 151 | 151 |
static int id(Node v) { return v.id; }
|
| 152 | 152 |
static int id(Arc e) { return e.id; }
|
| 153 | 153 |
|
| 154 | 154 |
static Node nodeFromId(int id) { return Node(id);}
|
| 155 | 155 |
static Arc arcFromId(int id) { return Arc(id);}
|
| 156 | 156 |
|
| 157 | 157 |
bool valid(Node n) const {
|
| 158 | 158 |
return n.id >= 0 && n.id < static_cast<int>(nodes.size()) && |
| 159 | 159 |
nodes[n.id].prev != -2; |
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 | 162 |
bool valid(Arc a) const {
|
| 163 | 163 |
return a.id >= 0 && a.id < static_cast<int>(arcs.size()) && |
| 164 | 164 |
arcs[a.id].prev_in != -2; |
| 165 | 165 |
} |
| 166 | 166 |
|
| 167 | 167 |
Node addNode() {
|
| 168 | 168 |
int n; |
| 169 | 169 |
|
| 170 | 170 |
if(first_free_node==-1) {
|
| 171 | 171 |
n = nodes.size(); |
| 172 | 172 |
nodes.push_back(NodeT()); |
| 173 | 173 |
} else {
|
| 174 | 174 |
n = first_free_node; |
| 175 | 175 |
first_free_node = nodes[n].next; |
| 176 | 176 |
} |
| 177 | 177 |
|
| 178 | 178 |
nodes[n].next = first_node; |
| 179 | 179 |
if(first_node != -1) nodes[first_node].prev = n; |
| 180 | 180 |
first_node = n; |
0 comments (0 inline)