src/work/alpar/smart_graph.h
changeset 115 3d9681ef6116
parent 108 0351b00fd283
child 116 a987c6013ea0
equal deleted inserted replaced
2:42ed4bf94468 3:6927693267aa
   280 
   280 
   281       DynNodeMap(SmartGraph &_G) :
   281       DynNodeMap(SmartGraph &_G) :
   282 	DynMapBase<NodeIt>(_G), container(_G.maxNodeId())
   282 	DynMapBase<NodeIt>(_G), container(_G.maxNodeId())
   283       {
   283       {
   284 	//FIXME: What if there are empty Id's?
   284 	//FIXME: What if there are empty Id's?
       
   285 	//FIXME: Can I use 'this' in a constructor?
   285 	G->dyn_node_maps.push_back(this);
   286 	G->dyn_node_maps.push_back(this);
   286       }
   287       }
   287       ~DynNodeMap()
   288       ~DynNodeMap()
   288       {
   289       {
   289 	if(G) {
   290 	if(G) {
   290 	  std::vector<DynMapBase<NodeIt>* >::iterator i;
   291 	  std::vector<DynMapBase<NodeIt>* >::iterator i;
   291 	  for(i=G->dyn_node_maps.begin();
   292 	  for(i=G->dyn_node_maps.begin();
   292 	      i!=G->dyn_node_maps.end() && *i!=this; ++i) ;
   293 	      i!=G->dyn_node_maps.end() && *i!=this; ++i) ;
   293 	  if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow...
   294 	  //if(*i==this) G->dyn_node_maps.erase(i); //FIXME: Way too slow...
       
   295 	  //A better way to do that: (Is this really important?)
       
   296 	  if(*i==this) {
       
   297 	    G->dyn_node_maps[i]=G->dyn_node_maps.back;
       
   298 	    G->dyn_node_maps.pop_back();
       
   299 	  }
   294 	}
   300 	}
   295       }
   301       }
   296 
   302 
   297       void add(const NodeIt k) 
   303       void add(const NodeIt k) 
   298       {
   304       {
   322 
   328 
   323       DynEdgeMap(SmartGraph &_G) :
   329       DynEdgeMap(SmartGraph &_G) :
   324 	DynMapBase<EdgeIt>(_G), container(_G.maxEdgeId())
   330 	DynMapBase<EdgeIt>(_G), container(_G.maxEdgeId())
   325       {
   331       {
   326 	//FIXME: What if there are empty Id's?
   332 	//FIXME: What if there are empty Id's?
   327 	//FIXME: Can I do that? :
   333 	//FIXME: Can I use 'this' in a constructor?
   328 	G->dyn_edge_maps.push_back(this);
   334 	G->dyn_edge_maps.push_back(this);
   329       }
   335       }
   330       ~DynEdgeMap()
   336       ~DynEdgeMap()
   331       {
   337       {
   332 	if(G) {
   338 	if(G) {
   333 	  std::vector<DynMapBase<EdgeIt>* >::iterator i;
   339 	  std::vector<DynMapBase<EdgeIt>* >::iterator i;
   334 	  for(i=G->dyn_edge_maps.begin();
   340 	  for(i=G->dyn_edge_maps.begin();
   335 	      i!=G->dyn_edge_maps.end() && *i!=this; ++i) ;
   341 	      i!=G->dyn_edge_maps.end() && *i!=this; ++i) ;
   336 	  if(*i==this) G->dyn_edge_maps.erase(i); //FIXME: Way too slow...
   342 	  //if(*i==this) G->dyn_edge_maps.erase(i); //Way too slow...
       
   343 	  //A better way to do that: (Is this really important?)
       
   344 	  if(*i==this) {
       
   345 	    G->dyn_edge_maps[i]=G->dyn_edge_maps.back;
       
   346 	    G->dyn_edge_maps.pop_back();
       
   347 	  }
   337 	}
   348 	}
   338       }
   349       }
   339 
   350       
   340       void add(const EdgeIt k) 
   351       void add(const EdgeIt k) 
   341       {
   352       {
   342 	if(k.n>=int(container.size())) container.resize(k.n+1);
   353 	if(k.n>=int(container.size())) container.resize(k.n+1);
   343       }
   354       }
   344       void erase(const EdgeIt k)
   355       void erase(const EdgeIt k)