Skip to content

Commit

Permalink
Merge pull request #12 from iamtheburd/further-optimize-memory
Browse files Browse the repository at this point in the history
Further optimize memory
  • Loading branch information
Tyler Burdsall authored Dec 27, 2018
2 parents 4d40aa9 + 0e4ac7b commit fb787db
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 21 deletions.
15 changes: 7 additions & 8 deletions src/boost_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,7 @@ const void parse_args(const generation_args &args)
}
else
{
set<uint1024_t> range = lazy_cartesian_product::boost_generate_random_indices(args.sample_size, max_size);
generate_random_samples(range, args);
generate_random_samples(max_size, args);
}
exit(0);
}
Expand All @@ -99,7 +98,7 @@ const void parse_args(const generation_args &args)
}
}

const void generate_random_samples(const set<uint1024_t> &range, const generation_args &args)
const void generate_random_samples(const uint1024_t &max_size, const generation_args &args)
{
if (!args.display_json)
{
Expand All @@ -112,16 +111,16 @@ const void generate_random_samples(const set<uint1024_t> &range, const generatio
{
cout << "[\n";
}
set<uint1024_t>::const_iterator i = range.begin();
while (i != range.end())
const uint1024_t parsed_sample_size(args.sample_size);
lazycp::RandomIterator iter(parsed_sample_size, max_size - 1);
while (iter.has_next())
{
vector<string> result = lazy_cartesian_product::boost_entry_at(args.pc.combinations, (*i).convert_to<string>());
vector<string> result = lazy_cartesian_product::boost_entry_at(args.pc.combinations, iter.next().convert_to<string>());
output_result(result, args, true);
if (args.display_json && i != range.end())
if (args.display_json && iter.has_next())
{
cout << ",";
}
++i;
}
if (args.display_json)
{
Expand Down
15 changes: 7 additions & 8 deletions src/combigen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ const void parse_args(const generation_args &args)
}
else
{
set<unsigned long long> range = lazy_cartesian_product::generate_random_indices(n, max_size);
generate_random_samples(range, args);
generate_random_samples(max_size, args);
}
exit(0);
}
Expand Down Expand Up @@ -127,7 +126,7 @@ const void generate_all(const unsigned long long &max_size, const generation_arg
}
}

const void generate_random_samples(const set<unsigned long long> &range, const generation_args &args)
const void generate_random_samples(const unsigned long long &max_size, const generation_args &args)
{
if (!args.display_json)
{
Expand All @@ -140,16 +139,16 @@ const void generate_random_samples(const set<unsigned long long> &range, const g
{
cout << "[\n";
}
set<unsigned long long>::const_iterator i = range.begin();
while (i != range.end())
unsigned long long parsed_sample_size = stoull(args.sample_size);
lazycp::RandomIterator iter(parsed_sample_size, max_size - 1);
while (iter.has_next())
{
vector<string> result = lazy_cartesian_product::entry_at(args.pc.combinations, *i);
vector<string> result = lazy_cartesian_product::entry_at(args.pc.combinations, iter.next());
output_result(result, args, true);
if (args.display_json && i != range.end())
if (args.display_json && iter.has_next())
{
cout << ",";
}
++i;
}
if (args.display_json)
{
Expand Down
4 changes: 2 additions & 2 deletions src/combigen.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ struct generation_args

#ifdef USE_BOOST
const void generate_all(const uint1024_t &max_size, const generation_args &args);
const void generate_random_samples(const set<uint1024_t> &range, const generation_args &args);
const void generate_random_samples(const uint1024_t &max_size, const generation_args &args);
#else
const void generate_all(const unsigned long long &max_size, const generation_args &args);
const void generate_random_samples(const set<unsigned long long> &range, const generation_args &args);
const void generate_random_samples(const unsigned long long &max_size, const generation_args &args);
#endif
const void generate_random_samples_performance_mode(const generation_args &args);
const void generate_random_samples_memory_mode(const generation_args &args);
Expand Down
2 changes: 1 addition & 1 deletion src/lib/iamtheburd/lazy-cartesian-product
6 changes: 4 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
#define MAIN

#define COMBIGEN_MAJOR_VERSION 1
#define COMBIGEN_MINOR_VERSION 3
#define COMBIGEN_REVISION_VERSION 2
#define COMBIGEN_MINOR_VERSION 4
#define COMBIGEN_REVISION_VERSION 0

#if defined(WIN32) || defined(_WIN32) || defined(__WIN32) && !defined(__CYGWIN__)
#include "lib/win-getopt/getopt.h"
Expand Down Expand Up @@ -101,12 +101,14 @@ int main(int argc, char* argv[])
break;
case 'k':
args_provided = true;
args.display_keys = true;
break;
case 'v':
cout << "combigen - v" << COMBIGEN_MAJOR_VERSION << '.' << COMBIGEN_MINOR_VERSION << '.' << COMBIGEN_REVISION_VERSION << '\n';
exit(0);
case 'p':
args.perf_mode = true;
args_provided = true;
break;
default:
display_help();
Expand Down

0 comments on commit fb787db

Please sign in to comment.