gravatar
alpar (Alpar Juttner)
alpar@cs.elte.hu
Merge
0 1 0
merge default
1 file changed with 3 insertions and 1 deletions:
↑ Collapse diff ↑
Ignore white space 96 line context
... ...
@@ -260,97 +260,99 @@
260 260
    /// \sa reserveNode
261 261
    void reserveArc(int m) { arcs.reserve(m); };
262 262

	
263 263
    /// \brief Node validity check
264 264
    ///
265 265
    /// This function gives back true if the given node is valid,
266 266
    /// ie. it is a real node of the graph.
267 267
    ///
268 268
    /// \warning A removed node (using Snapshot) could become valid again
269 269
    /// when new nodes are added to the graph.
270 270
    bool valid(Node n) const { return Parent::valid(n); }
271 271

	
272 272
    /// \brief Arc validity check
273 273
    ///
274 274
    /// This function gives back true if the given arc is valid,
275 275
    /// ie. it is a real arc of the graph.
276 276
    ///
277 277
    /// \warning A removed arc (using Snapshot) could become valid again
278 278
    /// when new arcs are added to the graph.
279 279
    bool valid(Arc a) const { return Parent::valid(a); }
280 280

	
281 281
    ///Clear the digraph.
282 282

	
283 283
    ///Erase all the nodes and arcs from the digraph.
284 284
    ///
285 285
    void clear() {
286 286
      Parent::clear();
287 287
    }
288 288

	
289 289
    ///Split a node.
290 290

	
291 291
    ///This function splits a node. First a new node is added to the digraph,
292 292
    ///then the source of each outgoing arc of \c n is moved to this new node.
293 293
    ///If \c connect is \c true (this is the default value), then a new arc
294 294
    ///from \c n to the newly created node is also added.
295 295
    ///\return The newly created node.
296 296
    ///
297 297
    ///\note The <tt>Arc</tt>s
298 298
    ///referencing a moved arc remain
299 299
    ///valid. However <tt>InArc</tt>'s and <tt>OutArc</tt>'s
300 300
    ///may be invalidated.
301 301
    ///\warning This functionality cannot be used together with the Snapshot
302 302
    ///feature.
303 303
    Node split(Node n, bool connect = true)
304 304
    {
305 305
      Node b = addNode();
306 306
      nodes[b._id].first_out=nodes[n._id].first_out;
307 307
      nodes[n._id].first_out=-1;
308
      for(int i=nodes[b._id].first_out;i!=-1;i++) arcs[i].source=b._id;
308
      for(int i=nodes[b._id].first_out; i!=-1; i=arcs[i].next_out) {
309
        arcs[i].source=b._id;
310
      }
309 311
      if(connect) addArc(n,b);
310 312
      return b;
311 313
    }
312 314

	
313 315
  public:
314 316

	
315 317
    class Snapshot;
316 318

	
317 319
  protected:
318 320

	
319 321
    void restoreSnapshot(const Snapshot &s)
320 322
    {
321 323
      while(s.arc_num<arcs.size()) {
322 324
        Arc arc = arcFromId(arcs.size()-1);
323 325
        Parent::notifier(Arc()).erase(arc);
324 326
        nodes[arcs.back().source].first_out=arcs.back().next_out;
325 327
        nodes[arcs.back().target].first_in=arcs.back().next_in;
326 328
        arcs.pop_back();
327 329
      }
328 330
      while(s.node_num<nodes.size()) {
329 331
        Node node = nodeFromId(nodes.size()-1);
330 332
        Parent::notifier(Node()).erase(node);
331 333
        nodes.pop_back();
332 334
      }
333 335
    }
334 336

	
335 337
  public:
336 338

	
337 339
    ///Class to make a snapshot of the digraph and to restrore to it later.
338 340

	
339 341
    ///Class to make a snapshot of the digraph and to restrore to it later.
340 342
    ///
341 343
    ///The newly added nodes and arcs can be removed using the
342 344
    ///restore() function.
343 345
    ///\note After you restore a state, you cannot restore
344 346
    ///a later state, in other word you cannot add again the arcs deleted
345 347
    ///by restore() using another one Snapshot instance.
346 348
    ///
347 349
    ///\warning If you do not use correctly the snapshot that can cause
348 350
    ///either broken program, invalid state of the digraph, valid but
349 351
    ///not the restored digraph or no change. Because the runtime performance
350 352
    ///the validity of the snapshot is not stored.
351 353
    class Snapshot
352 354
    {
353 355
      SmartDigraph *_graph;
354 356
    protected:
355 357
      friend class SmartDigraph;
356 358
      unsigned int node_num;
0 comments (0 inline)