Skip to content

Commit d696562

Browse files
author
Tyler Burdsall
authored
Merge pull request #10 from iamtheburd/reduce-memory-usage
Reduce memory usage
2 parents 2fcf7ee + eac64d3 commit d696562

File tree

5 files changed

+20
-22
lines changed

5 files changed

+20
-22
lines changed

src/boost_functions.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ const void parse_args(const generation_args &args)
8686
}
8787
else
8888
{
89-
vector<uint1024_t> range = lazy_cartesian_product::boost_generate_random_indices(args.sample_size, max_size);
89+
set<uint1024_t> range = lazy_cartesian_product::boost_generate_random_indices(args.sample_size, max_size);
9090
generate_random_samples(range, args);
9191
}
9292
exit(0);
@@ -99,7 +99,7 @@ const void parse_args(const generation_args &args)
9999
}
100100
}
101101

102-
const void generate_random_samples(const vector<uint1024_t> &range, const generation_args &args)
102+
const void generate_random_samples(const set<uint1024_t> &range, const generation_args &args)
103103
{
104104
if (!args.display_json)
105105
{
@@ -112,14 +112,16 @@ const void generate_random_samples(const vector<uint1024_t> &range, const genera
112112
{
113113
cout << "[\n";
114114
}
115-
for (const uint1024_t &i: range)
115+
set<uint1024_t>::const_iterator i = range.begin();
116+
while (i != range.end())
116117
{
117-
vector<string> result = lazy_cartesian_product::boost_entry_at(args.pc.combinations, i.convert_to<string>());
118+
vector<string> result = lazy_cartesian_product::boost_entry_at(args.pc.combinations, (*i).convert_to<string>());
118119
output_result(result, args, true);
119-
if (args.display_json && &i != &range.back())
120+
if (args.display_json && i != range.end())
120121
{
121122
cout << ",";
122123
}
124+
++i;
123125
}
124126
if (args.display_json)
125127
{

src/combigen.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const void parse_args(const generation_args &args)
8484
}
8585
else
8686
{
87-
vector<unsigned long long> range = lazy_cartesian_product::generate_random_indices(n, max_size);
87+
set<unsigned long long> range = lazy_cartesian_product::generate_random_indices(n, max_size);
8888
generate_random_samples(range, args);
8989
}
9090
exit(0);
@@ -127,7 +127,7 @@ const void generate_all(const unsigned long long &max_size, const generation_arg
127127
}
128128
}
129129

130-
const void generate_random_samples(const vector<unsigned long long> &range, const generation_args &args)
130+
const void generate_random_samples(const set<unsigned long long> &range, const generation_args &args)
131131
{
132132
if (!args.display_json)
133133
{
@@ -140,14 +140,16 @@ const void generate_random_samples(const vector<unsigned long long> &range, cons
140140
{
141141
cout << "[\n";
142142
}
143-
for (const unsigned long long &i: range)
143+
set<unsigned long long>::const_iterator i = range.begin();
144+
while (i != range.end())
144145
{
145-
vector<string> result = lazy_cartesian_product::entry_at(args.pc.combinations, i);
146+
vector<string> result = lazy_cartesian_product::entry_at(args.pc.combinations, *i);
146147
output_result(result, args, true);
147-
if (args.display_json && &i != &range.back())
148+
if (args.display_json && i != range.end())
148149
{
149150
cout << ",";
150151
}
152+
++i;
151153
}
152154
if (args.display_json)
153155
{

src/combigen.h

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,7 @@
3030
#include "lib/nlohmann/json/single_include/nlohmann/json.hpp"
3131
#include "lib/iamtheburd/lazy-cartesian-product/lazy-cartesian-product.hpp"
3232

33-
#ifdef USE_BOOST
34-
#include <boost/container/vector.hpp>
35-
#include <boost/multiprecision/cpp_int.hpp>
36-
using boost::container::vector;
37-
using namespace boost::multiprecision;
38-
#else
39-
#include <vector>
40-
using std::vector;
33+
#ifndef USE_BOOST
4134
using std::stoull;
4235
#endif
4336

@@ -75,12 +68,13 @@ struct generation_args
7568

7669
#ifdef USE_BOOST
7770
const void generate_all(const uint1024_t &max_size, const generation_args &args);
78-
const void generate_random_samples(const vector<uint1024_t> &range, const generation_args &args);
71+
const void generate_random_samples(const set<uint1024_t> &range, const generation_args &args);
7972
#else
8073
const void generate_all(const unsigned long long &max_size, const generation_args &args);
81-
const void generate_random_samples(const vector<unsigned long long> &range, const generation_args &args);
74+
const void generate_random_samples(const set<unsigned long long> &range, const generation_args &args);
8275
#endif
8376
const void generate_random_samples_performance_mode(const generation_args &args);
77+
const void generate_random_samples_memory_mode(const generation_args &args);
8478
const void parse_args(const generation_args &args);
8579

8680
#endif

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
#define COMBIGEN_MAJOR_VERSION 1
2323
#define COMBIGEN_MINOR_VERSION 3
24-
#define COMBIGEN_REVISION_VERSION 0
24+
#define COMBIGEN_REVISION_VERSION 1
2525

2626
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
2727
#include "lib/win-getopt/getopt.h"

0 commit comments

Comments
 (0)