# Ticket #311: 311-4-e8953d052534.patch

File 311-4-e8953d052534.patch, 3.0 KB (added by Peter Kovacs, 10 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 Parent::clear(); } /// Reserve memory for nodes. /// Using this function, it is possible to avoid superfluous memory /// allocation: if you know that the graph you want to build will /// be large (e.g. it will contain millions of nodes and/or edges), /// then it is worth reserving space for this amount before starting /// to build the graph. /// \sa reserveEdge() void reserveNode(int n) { nodes.reserve(n); }; /// Reserve memory for edges. /// Using this function, it is possible to avoid superfluous memory /// allocation: if you know that the graph you want to build will /// be large (e.g. it will contain millions of nodes and/or edges), /// then it is worth reserving space for this amount before starting /// to build the graph. /// \sa reserveNode() void reserveEdge(int m) { arcs.reserve(2 * m); }; /// \brief Class to make a snapshot of the graph and restore /// it later. ///
• ## lemon/smart_graph.h

`diff --git a/lemon/smart_graph.h b/lemon/smart_graph.h`
 a Parent::clear(); } /// Reserve memory for nodes. /// Using this function, it is possible to avoid superfluous memory /// allocation: if you know that the graph you want to build will /// be large (e.g. it will contain millions of nodes and/or edges), /// then it is worth reserving space for this amount before starting /// to build the graph. /// \sa reserveEdge() void reserveNode(int n) { nodes.reserve(n); }; /// Reserve memory for edges. /// Using this function, it is possible to avoid superfluous memory /// allocation: if you know that the graph you want to build will /// be large (e.g. it will contain millions of nodes and/or edges), /// then it is worth reserving space for this amount before starting /// to build the graph. /// \sa reserveNode() void reserveEdge(int m) { arcs.reserve(2 * m); }; public: class Snapshot;
• ## test/digraph_test.cc

`diff --git a/test/digraph_test.cc b/test/digraph_test.cc`
 a checkGraphNodeList(G, 0); checkGraphArcList(G, 0); G.reserveNode(3); G.reserveArc(4); Node n1 = G.addNode(), n2 = G.addNode(),
• ## test/graph_test.cc

`diff --git a/test/graph_test.cc b/test/graph_test.cc`
 a checkGraphEdgeList(G, 0); checkGraphArcList(G, 0); G.reserveNode(3); G.reserveEdge(3); Node n1 = G.addNode(), n2 = G.addNode(),