gravatar
kpeter (Peter Kovacs)
kpeter@inf.elte.hu
Add a resize() function to HypercubeGraph (#311) just like the similar functions in other static graph structures, and extend the test files to check these functions.
0 3 0
default
3 files changed with 38 insertions and 1 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -287,7 +287,8 @@
287 287
  /// Two nodes are connected in the graph if and only if their indices
288 288
  /// differ only on one position in the binary form.
289 289
  /// This class is completely static and it needs constant memory space.
290
  /// Thus you can neither add nor delete nodes or edges.
290
  /// Thus you can neither add nor delete nodes or edges, however 
291
  /// the structure can be resized using resize().
291 292
  ///
292 293
  /// This type fully conforms to the \ref concepts::Graph "Graph concept".
293 294
  /// Most of its member functions and nested classes are documented
... ...
@@ -306,6 +307,21 @@
306 307
    /// Constructs a hypercube graph with \c dim dimensions.
307 308
    HypercubeGraph(int dim) { construct(dim); }
308 309

	
310
    /// \brief Resizes the graph
311
    ///
312
    /// This function resizes the graph. It fully destroys and
313
    /// rebuilds the structure, therefore the maps of the graph will be
314
    /// reallocated automatically and the previous values will be lost.
315
    void resize(int dim) {
316
      Parent::notifier(Arc()).clear();
317
      Parent::notifier(Edge()).clear();
318
      Parent::notifier(Node()).clear();
319
      construct(dim);
320
      Parent::notifier(Node()).build();
321
      Parent::notifier(Edge()).build();
322
      Parent::notifier(Arc()).build();
323
    }
324

	
309 325
    /// \brief The number of dimensions.
310 326
    ///
311 327
    /// Gives back the number of dimensions.
Ignore white space 6 line context
... ...
@@ -378,7 +378,12 @@
378 378
void checkFullDigraph(int num) {
379 379
  typedef FullDigraph Digraph;
380 380
  DIGRAPH_TYPEDEFS(Digraph);
381

	
381 382
  Digraph G(num);
383
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
384

	
385
  G.resize(num);
386
  check(G.nodeNum() == num && G.arcNum() == num * num, "Wrong size");
382 387

	
383 388
  checkGraphNodeList(G, num);
384 389
  checkGraphArcList(G, num * num);
Ignore white space 6 line context
... ...
@@ -270,6 +270,13 @@
270 270
  GRAPH_TYPEDEFS(Graph);
271 271

	
272 272
  Graph G(num);
273
  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
274
        "Wrong size");
275

	
276
  G.resize(num);
277
  check(G.nodeNum() == num && G.edgeNum() == num * (num - 1) / 2,
278
        "Wrong size");
279

	
273 280
  checkGraphNodeList(G, num);
274 281
  checkGraphEdgeList(G, num * (num - 1) / 2);
275 282

	
... ...
@@ -414,6 +421,10 @@
414 421
  check(G.width() == width, "Wrong column number");
415 422
  check(G.height() == height, "Wrong row number");
416 423

	
424
  G.resize(width, height);
425
  check(G.width() == width, "Wrong column number");
426
  check(G.height() == height, "Wrong row number");
427

	
417 428
  for (int i = 0; i < width; ++i) {
418 429
    for (int j = 0; j < height; ++j) {
419 430
      check(G.col(G(i, j)) == i, "Wrong column");
... ...
@@ -489,6 +500,11 @@
489 500
  GRAPH_TYPEDEFS(HypercubeGraph);
490 501

	
491 502
  HypercubeGraph G(dim);
503
  check(G.dimension() == dim, "Wrong dimension");
504

	
505
  G.resize(dim);
506
  check(G.dimension() == dim, "Wrong dimension");
507
  
492 508
  checkGraphNodeList(G, 1 << dim);
493 509
  checkGraphEdgeList(G, dim * (1 << (dim-1)));
494 510
  checkGraphArcList(G, dim * (1 << dim));
0 comments (0 inline)