lemon/list_graph.h
changeset 2385 096d83158d41
parent 2343 21587bc5922b
child 2386 81b47fc5c444
equal deleted inserted replaced
46:1a3b15663d86 47:25419a88d9cd
   525           for (int i = 0; i < (int)nodes.size(); ++i) {
   525           for (int i = 0; i < (int)nodes.size(); ++i) {
   526             snapshot.eraseNode(nodes[i]);
   526             snapshot.eraseNode(nodes[i]);
   527           }
   527           }
   528         }
   528         }
   529         virtual void build() {
   529         virtual void build() {
   530           NodeNotifier* notifier = getNotifier();
   530           NodeNotifier* _notifier = notifier();
   531           Node node;
   531           Node node;
   532           std::vector<Node> nodes;
   532           std::vector<Node> nodes;
   533           for (notifier->first(node); node != INVALID; notifier->next(node)) {
   533           for (_notifier->first(node); node != INVALID; 
       
   534                _notifier->next(node)) {
   534             nodes.push_back(node);
   535             nodes.push_back(node);
   535           }
   536           }
   536           for (int i = nodes.size() - 1; i >= 0; --i) {
   537           for (int i = nodes.size() - 1; i >= 0; --i) {
   537             snapshot.addNode(nodes[i]);
   538             snapshot.addNode(nodes[i]);
   538           }
   539           }
   539         }
   540         }
   540         virtual void clear() {
   541         virtual void clear() {
   541           NodeNotifier* notifier = getNotifier();
   542           NodeNotifier* _notifier = notifier();
   542           Node node;
   543           Node node;
   543           for (notifier->first(node); node != INVALID; notifier->next(node)) {
   544           for (_notifier->first(node); node != INVALID; 
       
   545                _notifier->next(node)) {
   544             snapshot.eraseNode(node);
   546             snapshot.eraseNode(node);
   545           }
   547           }
   546         }
   548         }
   547 
   549 
   548         Snapshot& snapshot;
   550         Snapshot& snapshot;
   575           for (int i = 0; i < (int)edges.size(); ++i) {
   577           for (int i = 0; i < (int)edges.size(); ++i) {
   576             snapshot.eraseEdge(edges[i]);
   578             snapshot.eraseEdge(edges[i]);
   577           }
   579           }
   578         }
   580         }
   579         virtual void build() {
   581         virtual void build() {
   580           EdgeNotifier* notifier = getNotifier();
   582           EdgeNotifier* _notifier = notifier();
   581           Edge edge;
   583           Edge edge;
   582           std::vector<Edge> edges;
   584           std::vector<Edge> edges;
   583           for (notifier->first(edge); edge != INVALID; notifier->next(edge)) {
   585           for (_notifier->first(edge); edge != INVALID; 
       
   586                _notifier->next(edge)) {
   584             edges.push_back(edge);
   587             edges.push_back(edge);
   585           }
   588           }
   586           for (int i = edges.size() - 1; i >= 0; --i) {
   589           for (int i = edges.size() - 1; i >= 0; --i) {
   587             snapshot.addEdge(edges[i]);
   590             snapshot.addEdge(edges[i]);
   588           }
   591           }
   589         }
   592         }
   590         virtual void clear() {
   593         virtual void clear() {
   591           EdgeNotifier* notifier = getNotifier();
   594           EdgeNotifier* _notifier = notifier();
   592           Edge edge;
   595           Edge edge;
   593           for (notifier->first(edge); edge != INVALID; notifier->next(edge)) {
   596           for (_notifier->first(edge); edge != INVALID; _notifier->next(edge)) {
   594             snapshot.eraseEdge(edge);
   597             snapshot.eraseEdge(edge);
   595           }
   598           }
   596         }
   599         }
   597 
   600 
   598         Snapshot& snapshot;
   601         Snapshot& snapshot;
   637         }        
   640         }        
   638       }
   641       }
   639 
   642 
   640       void attach(ListGraph &_graph) {
   643       void attach(ListGraph &_graph) {
   641 	graph = &_graph;
   644 	graph = &_graph;
   642 	node_observer_proxy.attach(graph->getNotifier(Node()));
   645 	node_observer_proxy.attach(graph->notifier(Node()));
   643         edge_observer_proxy.attach(graph->getNotifier(Edge()));
   646         edge_observer_proxy.attach(graph->notifier(Edge()));
   644       }
   647       }
   645             
   648             
   646       void detach() {
   649       void detach() {
   647 	node_observer_proxy.detach();
   650 	node_observer_proxy.detach();
   648 	edge_observer_proxy.detach();
   651 	edge_observer_proxy.detach();
   909       if (e.id == -2) e.id = -1;
   912       if (e.id == -2) e.id = -1;
   910     }
   913     }
   911 
   914 
   912     void firstInc(UEdge &e, bool& d, const Node& v) const {
   915     void firstInc(UEdge &e, bool& d, const Node& v) const {
   913       int de = nodes[v.id].first_out;
   916       int de = nodes[v.id].first_out;
   914       e.id = de / 2;
   917       if (de != -1 ) {
   915       d = ((de & 1) == 1);
   918         e.id = de / 2;
       
   919         d = ((de & 1) == 1);
       
   920       } else {
       
   921         e.id = -1;
       
   922         d = true;
       
   923       }
   916     }
   924     }
   917     void nextInc(UEdge &e, bool& d) const {
   925     void nextInc(UEdge &e, bool& d) const {
   918       int de = (edges[(e.id * 2) | (d ? 1 : 0)].next_out);
   926       int de = (edges[(e.id * 2) | (d ? 1 : 0)].next_out);
   919       e.id = de / 2;
   927       if (de != -1 ) {
   920       d = ((de & 1) == 1);
   928         e.id = de / 2;
       
   929         d = ((de & 1) == 1);
       
   930       } else {
       
   931         e.id = -1;
       
   932         d = true;
       
   933       }
   921     }
   934     }
   922     
   935     
   923     static int id(Node v) { return v.id; }
   936     static int id(Node v) { return v.id; }
   924     static int id(Edge e) { return e.id; }
   937     static int id(Edge e) { return e.id; }
   925     static int id(UEdge e) { return e.id; }
   938     static int id(UEdge e) { return e.id; }
  1259           for (int i = 0; i < (int)nodes.size(); ++i) {
  1272           for (int i = 0; i < (int)nodes.size(); ++i) {
  1260             snapshot.eraseNode(nodes[i]);
  1273             snapshot.eraseNode(nodes[i]);
  1261           }
  1274           }
  1262         }
  1275         }
  1263         virtual void build() {
  1276         virtual void build() {
  1264           NodeNotifier* notifier = getNotifier();
  1277           NodeNotifier* _notifier = notifier();
  1265           Node node;
  1278           Node node;
  1266           std::vector<Node> nodes;
  1279           std::vector<Node> nodes;
  1267           for (notifier->first(node); node != INVALID; notifier->next(node)) {
  1280           for (_notifier->first(node); node != INVALID; 
       
  1281                _notifier->next(node)) {
  1268             nodes.push_back(node);
  1282             nodes.push_back(node);
  1269           }
  1283           }
  1270           for (int i = nodes.size() - 1; i >= 0; --i) {
  1284           for (int i = nodes.size() - 1; i >= 0; --i) {
  1271             snapshot.addNode(nodes[i]);
  1285             snapshot.addNode(nodes[i]);
  1272           }
  1286           }
  1273         }
  1287         }
  1274         virtual void clear() {
  1288         virtual void clear() {
  1275           NodeNotifier* notifier = getNotifier();
  1289           NodeNotifier* _notifier = notifier();
  1276           Node node;
  1290           Node node;
  1277           for (notifier->first(node); node != INVALID; notifier->next(node)) {
  1291           for (_notifier->first(node); node != INVALID; 
       
  1292                _notifier->next(node)) {
  1278             snapshot.eraseNode(node);
  1293             snapshot.eraseNode(node);
  1279           }
  1294           }
  1280         }
  1295         }
  1281 
  1296 
  1282         Snapshot& snapshot;
  1297         Snapshot& snapshot;
  1309           for (int i = 0; i < (int)edges.size(); ++i) {
  1324           for (int i = 0; i < (int)edges.size(); ++i) {
  1310             snapshot.eraseUEdge(edges[i]);
  1325             snapshot.eraseUEdge(edges[i]);
  1311           }
  1326           }
  1312         }
  1327         }
  1313         virtual void build() {
  1328         virtual void build() {
  1314           UEdgeNotifier* notifier = getNotifier();
  1329           UEdgeNotifier* _notifier = notifier();
  1315           UEdge edge;
  1330           UEdge edge;
  1316           std::vector<UEdge> edges;
  1331           std::vector<UEdge> edges;
  1317           for (notifier->first(edge); edge != INVALID; notifier->next(edge)) {
  1332           for (_notifier->first(edge); edge != INVALID; 
       
  1333                _notifier->next(edge)) {
  1318             edges.push_back(edge);
  1334             edges.push_back(edge);
  1319           }
  1335           }
  1320           for (int i = edges.size() - 1; i >= 0; --i) {
  1336           for (int i = edges.size() - 1; i >= 0; --i) {
  1321             snapshot.addUEdge(edges[i]);
  1337             snapshot.addUEdge(edges[i]);
  1322           }
  1338           }
  1323         }
  1339         }
  1324         virtual void clear() {
  1340         virtual void clear() {
  1325           UEdgeNotifier* notifier = getNotifier();
  1341           UEdgeNotifier* _notifier = notifier();
  1326           UEdge edge;
  1342           UEdge edge;
  1327           for (notifier->first(edge); edge != INVALID; notifier->next(edge)) {
  1343           for (_notifier->first(edge); edge != INVALID; 
       
  1344                _notifier->next(edge)) {
  1328             snapshot.eraseUEdge(edge);
  1345             snapshot.eraseUEdge(edge);
  1329           }
  1346           }
  1330         }
  1347         }
  1331 
  1348 
  1332         Snapshot& snapshot;
  1349         Snapshot& snapshot;
  1371         }        
  1388         }        
  1372       }
  1389       }
  1373 
  1390 
  1374       void attach(ListUGraph &_graph) {
  1391       void attach(ListUGraph &_graph) {
  1375 	graph = &_graph;
  1392 	graph = &_graph;
  1376 	node_observer_proxy.attach(graph->getNotifier(Node()));
  1393 	node_observer_proxy.attach(graph->notifier(Node()));
  1377         edge_observer_proxy.attach(graph->getNotifier(UEdge()));
  1394         edge_observer_proxy.attach(graph->notifier(UEdge()));
  1378       }
  1395       }
  1379             
  1396             
  1380       void detach() {
  1397       void detach() {
  1381 	node_observer_proxy.detach();
  1398 	node_observer_proxy.detach();
  1382 	edge_observer_proxy.detach();
  1399 	edge_observer_proxy.detach();
  2037           for (int i = 0; i < (int)nodes.size(); ++i) {
  2054           for (int i = 0; i < (int)nodes.size(); ++i) {
  2038             snapshot.eraseNode(nodes[i]);
  2055             snapshot.eraseNode(nodes[i]);
  2039           }
  2056           }
  2040         }
  2057         }
  2041         virtual void build() {
  2058         virtual void build() {
  2042           NodeNotifier* notifier = getNotifier();
  2059           NodeNotifier* _notifier = notifier();
  2043           Node node;
  2060           Node node;
  2044           std::vector<Node> nodes;
  2061           std::vector<Node> nodes;
  2045           for (notifier->first(node); node != INVALID; notifier->next(node)) {
  2062           for (_notifier->first(node); node != INVALID; 
       
  2063                _notifier->next(node)) {
  2046             nodes.push_back(node);
  2064             nodes.push_back(node);
  2047           }
  2065           }
  2048           for (int i = nodes.size() - 1; i >= 0; --i) {
  2066           for (int i = nodes.size() - 1; i >= 0; --i) {
  2049             snapshot.addNode(nodes[i]);
  2067             snapshot.addNode(nodes[i]);
  2050           }
  2068           }
  2051         }
  2069         }
  2052         virtual void clear() {
  2070         virtual void clear() {
  2053           NodeNotifier* notifier = getNotifier();
  2071           NodeNotifier* _notifier = notifier();
  2054           Node node;
  2072           Node node;
  2055           for (notifier->first(node); node != INVALID; notifier->next(node)) {
  2073           for (_notifier->first(node); node != INVALID; 
       
  2074                _notifier->next(node)) {
  2056             snapshot.eraseNode(node);
  2075             snapshot.eraseNode(node);
  2057           }
  2076           }
  2058         }
  2077         }
  2059 
  2078 
  2060         Snapshot& snapshot;
  2079         Snapshot& snapshot;
  2087           for (int i = 0; i < (int)edges.size(); ++i) {
  2106           for (int i = 0; i < (int)edges.size(); ++i) {
  2088             snapshot.eraseUEdge(edges[i]);
  2107             snapshot.eraseUEdge(edges[i]);
  2089           }
  2108           }
  2090         }
  2109         }
  2091         virtual void build() {
  2110         virtual void build() {
  2092           UEdgeNotifier* notifier = getNotifier();
  2111           UEdgeNotifier* _notifier = notifier();
  2093           UEdge edge;
  2112           UEdge edge;
  2094           std::vector<UEdge> edges;
  2113           std::vector<UEdge> edges;
  2095           for (notifier->first(edge); edge != INVALID; notifier->next(edge)) {
  2114           for (_notifier->first(edge); edge != INVALID; 
       
  2115                _notifier->next(edge)) {
  2096             edges.push_back(edge);
  2116             edges.push_back(edge);
  2097           }
  2117           }
  2098           for (int i = edges.size() - 1; i >= 0; --i) {
  2118           for (int i = edges.size() - 1; i >= 0; --i) {
  2099             snapshot.addUEdge(edges[i]);
  2119             snapshot.addUEdge(edges[i]);
  2100           }
  2120           }
  2101         }
  2121         }
  2102         virtual void clear() {
  2122         virtual void clear() {
  2103           UEdgeNotifier* notifier = getNotifier();
  2123           UEdgeNotifier* _notifier = notifier();
  2104           UEdge edge;
  2124           UEdge edge;
  2105           for (notifier->first(edge); edge != INVALID; notifier->next(edge)) {
  2125           for (_notifier->first(edge); edge != INVALID; 
       
  2126                _notifier->next(edge)) {
  2106             snapshot.eraseUEdge(edge);
  2127             snapshot.eraseUEdge(edge);
  2107           }
  2128           }
  2108         }
  2129         }
  2109 
  2130 
  2110         Snapshot& snapshot;
  2131         Snapshot& snapshot;
  2149         }        
  2170         }        
  2150       }
  2171       }
  2151 
  2172 
  2152       void attach(ListBpUGraph &_graph) {
  2173       void attach(ListBpUGraph &_graph) {
  2153 	graph = &_graph;
  2174 	graph = &_graph;
  2154 	node_observer_proxy.attach(graph->getNotifier(Node()));
  2175 	node_observer_proxy.attach(graph->notifier(Node()));
  2155         edge_observer_proxy.attach(graph->getNotifier(UEdge()));
  2176         edge_observer_proxy.attach(graph->notifier(UEdge()));
  2156       }
  2177       }
  2157             
  2178             
  2158       void detach() {
  2179       void detach() {
  2159 	node_observer_proxy.detach();
  2180 	node_observer_proxy.detach();
  2160 	edge_observer_proxy.detach();
  2181 	edge_observer_proxy.detach();