diff --git a/src/include/client.h b/src/include/client.h index b98a91b..9ab21f4 100644 --- a/src/include/client.h +++ b/src/include/client.h @@ -10,11 +10,10 @@ #include #include #include -#include -#include - #include #include +#include +#include #include "data.h" #include "zb64.h" @@ -27,42 +26,35 @@ bool already_have[14348907]; int rid[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; int cid[15] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4}; class HashTable { + static const int buf_size=44348907; struct Node { LL key; unsigned char value; Node *next; - Node(LL k, unsigned char v) : key(k), value(v), next(nullptr) {} + // Node(LL k, unsigned char v) : key(k), value(v), next(nullptr) {} }; - Node *table[14348907]; + Node *table[buf_size], mem[buf_size], *cur = mem; public: HashTable() { - for (int i = 0; i < 14348907; i++) table[i] = nullptr; - } - ~HashTable() { - for (int i = 0; i < 14348907; i++) { - Node *p = table[i]; - while (p) { - Node *q = p->next; - delete p; - p = q; - } - } + for (int i = 0; i < buf_size; i++) table[i] = nullptr; } + ~HashTable() {} unsigned char &operator[](LL key) { - int index = key % 14348907; + int index = key % buf_size; Node *p = table[index]; while (p) { if (p->key == key) return p->value; p = p->next; } - p = new Node(key, 0); + p = cur++; + p->key = key; p->next = table[index]; table[index] = p; return p->value; } bool have(LL key) { - int index = key % 14348907; + int index = key % buf_size; Node *p = table[index]; while (p) { if (p->key == key) return true; @@ -684,7 +676,7 @@ double EstimateProb(std::pair pos, double default_p = 0.06) { visible_status / (vis_line_base * vis_line_base); if (DataLoad::visible_to_probability.have(visible_status)) ps.push_back(DataLoad::visible_to_probability[visible_status] / 255.0); - if (DataLoad::visible_to_probability.have(invers_vis_status) ) + if (DataLoad::visible_to_probability.have(invers_vis_status)) ps.push_back(DataLoad::visible_to_probability[invers_vis_status] / 255.0); } for (int i = 0; i < ps.size(); i++) res += ps[i] * ps[i]; diff --git a/src/include/dataload.h b/src/include/dataload.h deleted file mode 100644 index 438563a..0000000 --- a/src/include/dataload.h +++ /dev/null @@ -1,109 +0,0 @@ -#include -#include - -#include "data.h" -#include "zb64.h" -namespace DataLoad { -typedef long long LL; -const int buf_size = 4412555 * 4; -unsigned char buf[buf_size], data[buf_size]; -bool already_have[14348907]; -// std::unordered_map visible_to_probability; -int rid[15] = {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 2, 2}; -int cid[15] = {0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 0, 1, 2, 3, 4}; -class HashTable { - struct Node { - LL key; - unsigned char value; - Node *next; - Node(LL k, unsigned char v) : key(k), value(v), next(nullptr) {} - }; - Node *table[14348907]; - - public: - HashTable() { - for (int i = 0; i < 14348907; i++) table[i] = nullptr; - } - ~HashTable() { - for (int i = 0; i < 14348907; i++) { - Node *p = table[i]; - while (p) { - Node *q = p->next; - delete p; - p = q; - } - } - } - unsigned char &operator[](LL key) { - int index = key % 14348907; - Node *p = table[index]; - while (p) { - if (p->key == key) return p->value; - p = p->next; - } - p = new Node(key, 0); - p->next = table[index]; - table[index] = p; - return p->value; - } - bool have(LL key) { - int index = key % 14348907; - Node *p = table[index]; - while (p) { - if (p->key == key) return true; - p = p->next; - } - return false; - } -} visible_to_probability; -} // namespace DataLoad -void LoadData() { - using namespace DataLoad; - size_t raw_length = base64_decode(pre_calc_prob, buf, buf_size); - size_t data_length = decompressData(buf, raw_length, data, buf_size); - // std::cout<<"decompress finished.\n"<= 3 || nc < 0 || nc >= 5) continue; - mcnt += (inner_mp[nr][nc] == 0 ? 1 : 0); - } - visible_map[row][col] = mcnt; - } - } - LL visible_status = 0; - for (int i = 0; i < 15; i++) { - int row = rid[i], col = cid[i]; - visible_status = visible_status * 10 + visible_map[row][col]; - } - visible_to_probability[visible_status] = data[cnt++]; - } - // std::cout<<"Load data finished.\n"<