Improved rank saving

Now using full bit mask instead of functions list
This commit is contained in:
2020-03-29 23:29:02 +03:00
parent 3c0d408989
commit 230f37c9bb

View File

@@ -259,25 +259,44 @@ size_t recover_ranks(vector< vector<MyFunction> >& ranks, vector<int8_t>& used_m
if ( not f_in.good() )
return rank_ind;
ranks.push_back(vector<MyFunction>());
while ( not f_in.eof() and f_in.good() ) {
char buf[sizeof(Storage)];
f_in.read(buf, sizeof(Storage));
Storage function_value = *reinterpret_cast<Storage*>(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<char*>(&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<MyFunction>& 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<char*>(&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<char*>(&buf), 1);
}
}