diff --git a/main.cpp b/main.cpp index 01aaa58..3435b9e 100644 --- a/main.cpp +++ b/main.cpp @@ -259,25 +259,44 @@ size_t recover_ranks(vector< vector >& ranks, vector& used_m if ( not f_in.good() ) return rank_ind; ranks.push_back(vector()); - while ( not f_in.eof() and f_in.good() ) { - char buf[sizeof(Storage)]; - f_in.read(buf, sizeof(Storage)); - Storage function_value = *reinterpret_cast(buf); - MyFunction f(function_value); - if (used_map.at(f.value())) - continue; - used_map.at(f.value()) = rank_ind; - --functions_remains; - ranks.back().push_back(f); + + for (Storage bytes_cnt = 0; bytes_cnt < FUNCTIONS_COUNT / 8; ++bytes_cnt) { + uint8_t buf; + f_in.read(reinterpret_cast(&buf), 1); + for (int8_t bits_cnt = 7; bits_cnt >= 0; --bits_cnt) { + bool is_exists = buf % 2; + if ( is_exists ) { + Storage function_value = bytes_cnt * 8 + bits_cnt; + MyFunction f(function_value); + if (used_map.at(f.value())) + continue; + used_map.at(f.value()) = rank_ind; + --functions_remains; + ranks.back().push_back(f); + } + buf /= 2; + } } } } void save_rank(size_t rank_ind, vector& rank_items) { + if ( not is_sorted(rank_items.begin(), rank_items.end()) ) + exit(1); ofstream f_out(get_out_file_name(rank_ind).c_str(), ios::binary); - for (auto f: rank_items) { - Storage function_value = f.value(); - f_out.write(reinterpret_cast(&function_value), sizeof(function_value)); + + size_t fn_ptr = 0; + + for (Storage bytes_cnt = 0; bytes_cnt < FUNCTIONS_COUNT / 8; ++bytes_cnt) { + uint8_t buf = 0; + for (Storage bits_cnt = 0; bits_cnt < 8; ++bits_cnt) { + buf *= 2; + if ( fn_ptr >= rank_items.size() or rank_items[fn_ptr].value() != bytes_cnt * 8 + bits_cnt ) + continue; + ++buf; + ++fn_ptr; + } + f_out.write(reinterpret_cast(&buf), 1); } }