# HG changeset patch
# User Peter Kovacs <kpeter@inf.elte.hu>
# Date 1226058174 -3600
# Node ID 3fe3c838a89e4cbaf1168b4f0720839bde2f44ce
# Parent 164fe3abc0249a97d773f6cfa7fd0d3c623b88a9
Constant time item counting for ListDigraph and ListGraph (#3)
diff --git a/lemon/list_graph.h b/lemon/list_graph.h
|
a
|
b
|
|
| 56 | 56 | |
| 57 | 57 | int first_free_arc; |
| 58 | 58 | |
| | 59 | int node_num, arc_num; |
| | 60 | |
| 59 | 61 | public: |
| 60 | 62 | |
| 61 | 63 | typedef ListDigraphBase Digraph; |
| … |
… |
|
| 91 | 93 | }; |
| 92 | 94 | |
| 93 | 95 | |
| | 96 | ListDigraphBase() |
| | 97 | : nodes(), first_node(-1), first_free_node(-1), |
| | 98 | arcs(), first_free_arc(-1), |
| | 99 | node_num(0), arc_num(0) {} |
| 94 | 100 | |
| 95 | | ListDigraphBase() |
| 96 | | : nodes(), first_node(-1), |
| 97 | | first_free_node(-1), arcs(), first_free_arc(-1) {} |
| 98 | 101 | |
| | 102 | typedef True NodeNumTag; |
| | 103 | typedef True ArcNumTag; |
| | 104 | |
| | 105 | int nodeNum() const { return node_num; } |
| | 106 | int arcNum() const { return arc_num; } |
| 99 | 107 | |
| 100 | 108 | int maxNodeId() const { return nodes.size()-1; } |
| 101 | 109 | int maxArcId() const { return arcs.size()-1; } |
| … |
… |
|
| 182 | 190 | |
| 183 | 191 | nodes[n].first_in = nodes[n].first_out = -1; |
| 184 | 192 | |
| | 193 | ++node_num; |
| | 194 | |
| 185 | 195 | return Node(n); |
| 186 | 196 | } |
| 187 | 197 | |
| … |
… |
|
| 213 | 223 | |
| 214 | 224 | nodes[u.id].first_out = nodes[v.id].first_in = n; |
| 215 | 225 | |
| | 226 | ++arc_num; |
| | 227 | |
| 216 | 228 | return Arc(n); |
| 217 | 229 | } |
| 218 | 230 | |
| … |
… |
|
| 233 | 245 | first_free_node = n; |
| 234 | 246 | nodes[n].prev = -2; |
| 235 | 247 | |
| | 248 | --node_num; |
| 236 | 249 | } |
| 237 | 250 | |
| 238 | 251 | void erase(const Arc& arc) { |
| … |
… |
|
| 262 | 275 | arcs[n].next_in = first_free_arc; |
| 263 | 276 | first_free_arc = n; |
| 264 | 277 | arcs[n].prev_in = -2; |
| | 278 | |
| | 279 | --arc_num; |
| 265 | 280 | } |
| 266 | 281 | |
| 267 | 282 | void clear() { |
| 268 | 283 | arcs.clear(); |
| 269 | 284 | nodes.clear(); |
| 270 | 285 | first_node = first_free_node = first_free_arc = -1; |
| | 286 | node_num = arc_num = 0; |
| 271 | 287 | } |
| 272 | 288 | |
| 273 | 289 | protected: |
| … |
… |
|
| 794 | 810 | |
| 795 | 811 | int first_free_arc; |
| 796 | 812 | |
| | 813 | int node_num, edge_num; |
| | 814 | |
| 797 | 815 | public: |
| 798 | 816 | |
| 799 | 817 | typedef ListGraphBase Digraph; |
| … |
… |
|
| 855 | 873 | |
| 856 | 874 | ListGraphBase() |
| 857 | 875 | : nodes(), first_node(-1), |
| 858 | | first_free_node(-1), arcs(), first_free_arc(-1) {} |
| | 876 | first_free_node(-1), arcs(), first_free_arc(-1), |
| | 877 | node_num(0), edge_num(0) {} |
| 859 | 878 | |
| | 879 | |
| | 880 | typedef True NodeNumTag; |
| | 881 | typedef True EdgeNumTag; |
| | 882 | typedef True ArcNumTag; |
| | 883 | |
| | 884 | int nodeNum() const { return node_num; } |
| | 885 | int edgeNum() const { return edge_num; } |
| | 886 | int arcNum() const { return edge_num * 2; } |
| 860 | 887 | |
| 861 | 888 | int maxNodeId() const { return nodes.size()-1; } |
| 862 | 889 | int maxEdgeId() const { return arcs.size() / 2 - 1; } |
| … |
… |
|
| 1023 | 1050 | |
| 1024 | 1051 | nodes[n].first_out = -1; |
| 1025 | 1052 | |
| | 1053 | ++node_num; |
| | 1054 | |
| 1026 | 1055 | return Node(n); |
| 1027 | 1056 | } |
| 1028 | 1057 | |
| … |
… |
|
| 1055 | 1084 | arcs[n | 1].prev_out = -1; |
| 1056 | 1085 | nodes[u.id].first_out = (n | 1); |
| 1057 | 1086 | |
| | 1087 | ++edge_num; |
| | 1088 | |
| 1058 | 1089 | return Edge(n / 2); |
| 1059 | 1090 | } |
| 1060 | 1091 | |
| … |
… |
|
| 1074 | 1105 | nodes[n].next = first_free_node; |
| 1075 | 1106 | first_free_node = n; |
| 1076 | 1107 | nodes[n].prev = -2; |
| | 1108 | |
| | 1109 | --node_num; |
| 1077 | 1110 | } |
| 1078 | 1111 | |
| 1079 | 1112 | void erase(const Edge& edge) { |
| … |
… |
|
| 1104 | 1137 | arcs[n].prev_out = -2; |
| 1105 | 1138 | arcs[n | 1].prev_out = -2; |
| 1106 | 1139 | |
| | 1140 | --edge_num; |
| 1107 | 1141 | } |
| 1108 | 1142 | |
| 1109 | 1143 | void clear() { |
| 1110 | 1144 | arcs.clear(); |
| 1111 | 1145 | nodes.clear(); |
| 1112 | 1146 | first_node = first_free_node = first_free_arc = -1; |
| | 1147 | node_num = edge_num = 0; |
| 1113 | 1148 | } |
| 1114 | 1149 | |
| 1115 | 1150 | protected: |