From 98bbd51a87d93af882fa8848b001309ab8eded53 Mon Sep 17 00:00:00 2001 From: Aleksey Lobanov Date: Thu, 26 Apr 2018 02:34:08 +0300 Subject: [PATCH] Current function state stored in vector --- main.cpp | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/main.cpp b/main.cpp index 34529ff..38799da 100644 --- a/main.cpp +++ b/main.cpp @@ -26,9 +26,9 @@ const CellType CUR_BASE = 3; const int ARGS_COUNT = 2; struct FunctionTask { - set> current; - bool is_finished; + vector> current; int current_max_coeff; + bool is_finished; }; template @@ -268,13 +268,13 @@ set> generate_function_class(FiniteFunction base_func // Вторым результатом возвращает true, если вычисления закончились успешно // и false, если прервались по достижению max_size template -pair>, bool> extend_function_class( - const set>& base_class, +pair>, bool> extend_function_class( + const vector>& base_class, size_t max_size ) { if ( base_class.size() >= max_size ) return make_pair( - set>(base_class.begin(), base_class.end()), + vector>(base_class.begin(), base_class.end()), false ); @@ -322,14 +322,15 @@ pair>, bool> extend_function_class( } } return make_pair( - set>(func_class.begin(), func_class.end()), + vector>(func_class.begin(), func_class.end()), is_finished ); } +template bool is_bad_class( - set> func_class, + const Iterable& func_class, const set>& bad_funcs ) { for (auto&& func: func_class) @@ -401,6 +402,9 @@ void process_task_lists() { continue; } task_mutex.lock(); + if ( task_list.size() != 0 ) + cout << "IMPOSSIBLE task_list.size!!" << endl; + task_list.clear(); task_list.shrink_to_fit(); task_mutex.unlock(); @@ -412,6 +416,11 @@ void process_task_lists() { processed_task_mutex.unlock(); cout << "sorting finished of "<< local_processed_tasks.size() << endl; + size_t total_funcs = 0; + for (auto&& task: local_processed_tasks) + total_funcs += task.current.size(); + cout << "estimated size: " + << sizeof(FunctionTask) * total_funcs / 1024 / 1024 << " MB" << endl; // Обеспечим увеличение размеров, чтобы не было проблем со включением одного // в другое sort( @@ -440,6 +449,7 @@ void process_task_lists() { //cout << "task finished, appending" << endl; ++completed_tasks; print_progress(completed_tasks, total_possible_functions); + sort(task.current.begin(), task.current.end()); auto func_class = task.current; bool is_need_append = true; vector functions_to_remove; @@ -471,7 +481,10 @@ void process_task_lists() { } } if ( is_need_append ) { - shared_function_classes.push_back(func_class); + shared_function_classes.push_back(set>( + func_class.begin(), + func_class.end() + )); for (auto&& func: func_class) bad_functions.insert(func); } @@ -490,6 +503,7 @@ void process_task_lists() { int main() { + cout << sizeof(FiniteFunction) << " " << sizeof(FunctionTask) << endl; auto FiniteFunctionHasher = [](const FiniteFunction &f) -> uint32_t { return f.get_hash(); }; @@ -518,14 +532,14 @@ int main() { FiniteFunction identical_x(string("000 111 222")); FiniteFunction identical_y(string("012 012 012")); - + allowed_functions.erase(identical_x); allowed_functions.erase(identical_y); completed_tasks = 0; for (auto&& func: allowed_functions) { FunctionTask task; - task.current.insert(func); + task.current = {func}; task.is_finished = false; task.current_max_coeff = 1; task_list.push_back(task);