Browse Source

feat: short code zip and unzip framework

master
Dnomd343 2 years ago
parent
commit
c13828ed61
  1. 36
      klotski/main.cc
  2. 33
      klotski/short_code.cc
  3. 17
      klotski/short_code.h

36
klotski/main.cc

@ -38,37 +38,13 @@ int main() {
// printf("%d\n", s.tiny_encode(0x6EC0F8800));
// printf("%09lX\n", s.tiny_decode(14323231));
// auto s = ShortCode();
// auto s = ShortCode(ShortCode::Mode::NORMAL);
auto s = ShortCode(ShortCode::Mode::FAST);
// if (CommonCode::check(0x4FEA13400)) {
// std::cout << "true" << std::endl;
// } else {
// std::cout << "false" << std::endl;
// }
// uint32_t sum = 0;
for (uint32_t head = 0; head < 16; ++head) {
auto prefix = (uint64_t)head << 32;
for (uint64_t range = 0; range < 0x100000000; ++range) {
uint64_t code = prefix | range;
if (CommonCode::check(code)) {
printf("%09lX\n", code);
// ++sum;
}
// if (range % 0x1000000 == 0) {
// std::cout << range / 0x1000000 << std::endl;
// }
}
}
// std::cout << "sum: " << sum << std::endl;
// uint64_t error_code = 0x02EFFF7C0;
// uint64_t error_code = 0x07B4EFC00;
// if (CommonCode::check(error_code)) {
// std::cout << "true" << std::endl;
// } else {
// std::cout << "false" << std::endl;
// }
std::cout << "start" << std::endl;
std::cout << s.check_mode() << std::endl;
std::cout << "complete" << std::endl;
return 0;
}

33
klotski/short_code.cc

@ -99,3 +99,36 @@ uint32_t ShortCode::tiny_encode(uint64_t common_code) {
}
return ALL_CASES_OFFSET[head] + RANGE_PREFIX_OFFSET[head][prefix] + offset;
}
uint32_t ShortCode::zip_short_code(uint64_t common_code) { // common_code --zip--> short_code
// TODO: confirm common_code valid
// TODO: check Mode => NORMAL / FAST
// TODO: usage fast_encode or tiny_encode
return 0;
}
uint64_t ShortCode::unzip_short_code(uint32_t short_code) { // short_code --unzip--> common_code
// TODO: confirm short_code valid
// TODO: check Mode => NORMAL / FAST
// TODO: usage fast_decode / tiny_decode
return 0;
}
enum ShortCode::Mode ShortCode::check_mode() { // ensure speed up enabled and return current mode
if (!all_cases_list.empty()) {
return ShortCode::Mode::FAST; // fast mode already enabled
}
if (!basic_ranges.empty()) {
return ShortCode::Mode::NORMAL; // normal mode already enabled
}
speed_up(ShortCode::Mode::NORMAL); // class without initialized -> enter normal mode
return ShortCode::Mode::NORMAL; // use normal mode
}

17
klotski/short_code.h

@ -18,19 +18,24 @@ public:
void speed_up(enum Mode mode);
explicit ShortCode(enum Mode mode);
// uint32_t zip_short_code(uint64_t code);
// uint64_t unzip_short_code(uint32_t short_code);
uint32_t zip_short_code(uint64_t common_code);
uint64_t unzip_short_code(uint32_t short_code);
uint64_t fast_decode(uint32_t short_code);
uint32_t fast_encode(uint64_t common_code);
enum Mode check_mode();
uint64_t tiny_decode(uint32_t short_code);
uint32_t tiny_encode(uint64_t common_code);
private:
// std::vector<uint64_t> all_cases_list; // short_code -> common_code
// std::unordered_map<uint64_t, uint32_t> all_cases_dict; // common_code -> short_code
const uint32_t SHORT_CODE_LIMIT = 29334498;
uint64_t fast_decode(uint32_t short_code);
uint32_t fast_encode(uint64_t common_code);
uint64_t tiny_decode(uint32_t short_code);
uint32_t tiny_encode(uint64_t common_code);
void build_mappings();
void build_base_ranges();

Loading…
Cancel
Save