COIN-OR::LEMON - Graph Library

Ticket #311: 311-4-e8953d052534.patch

File 311-4-e8953d052534.patch, 3.0 KB (added by Peter Kovacs, 15 years ago)
  • lemon/list_graph.h

    # HG changeset patch
    # User Peter Kovacs <kpeter@inf.elte.hu>
    # Date 1250787272 -7200
    # Node ID e8953d05253425a6d7ab6a41c0dd0c7ecf5af5d2
    # Parent  eef9c32052d08b43a8a9336942d44519af31637d
    Add reserve functions to ListGraph and SmartGraph (#311)
    ListDigraph and SmartDigraph already have such functions.
    
    diff --git a/lemon/list_graph.h b/lemon/list_graph.h
    a b  
    13111311      Parent::clear();
    13121312    }
    13131313
     1314    /// Reserve memory for nodes.
     1315
     1316    /// Using this function, it is possible to avoid superfluous memory
     1317    /// allocation: if you know that the graph you want to build will
     1318    /// be large (e.g. it will contain millions of nodes and/or edges),
     1319    /// then it is worth reserving space for this amount before starting
     1320    /// to build the graph.
     1321    /// \sa reserveEdge()
     1322    void reserveNode(int n) { nodes.reserve(n); };
     1323
     1324    /// Reserve memory for edges.
     1325
     1326    /// Using this function, it is possible to avoid superfluous memory
     1327    /// allocation: if you know that the graph you want to build will
     1328    /// be large (e.g. it will contain millions of nodes and/or edges),
     1329    /// then it is worth reserving space for this amount before starting
     1330    /// to build the graph.
     1331    /// \sa reserveNode()
     1332    void reserveEdge(int m) { arcs.reserve(2 * m); };
     1333
    13141334    /// \brief Class to make a snapshot of the graph and restore
    13151335    /// it later.
    13161336    ///
  • lemon/smart_graph.h

    diff --git a/lemon/smart_graph.h b/lemon/smart_graph.h
    a b  
    691691      Parent::clear();
    692692    }
    693693
     694    /// Reserve memory for nodes.
     695
     696    /// Using this function, it is possible to avoid superfluous memory
     697    /// allocation: if you know that the graph you want to build will
     698    /// be large (e.g. it will contain millions of nodes and/or edges),
     699    /// then it is worth reserving space for this amount before starting
     700    /// to build the graph.
     701    /// \sa reserveEdge()
     702    void reserveNode(int n) { nodes.reserve(n); };
     703
     704    /// Reserve memory for edges.
     705
     706    /// Using this function, it is possible to avoid superfluous memory
     707    /// allocation: if you know that the graph you want to build will
     708    /// be large (e.g. it will contain millions of nodes and/or edges),
     709    /// then it is worth reserving space for this amount before starting
     710    /// to build the graph.
     711    /// \sa reserveNode()
     712    void reserveEdge(int m) { arcs.reserve(2 * m); };
     713
    694714  public:
    695715
    696716    class Snapshot;
  • test/digraph_test.cc

    diff --git a/test/digraph_test.cc b/test/digraph_test.cc
    a b  
    3535  checkGraphNodeList(G, 0);
    3636  checkGraphArcList(G, 0);
    3737
     38  G.reserveNode(3);
     39  G.reserveArc(4);
     40
    3841  Node
    3942    n1 = G.addNode(),
    4043    n2 = G.addNode(),
  • test/graph_test.cc

    diff --git a/test/graph_test.cc b/test/graph_test.cc
    a b  
    3838  checkGraphEdgeList(G, 0);
    3939  checkGraphArcList(G, 0);
    4040
     41  G.reserveNode(3);
     42  G.reserveEdge(3);
     43
    4144  Node
    4245    n1 = G.addNode(),
    4346    n2 = G.addNode(),