diff --git a/klotski/main.cc b/klotski/main.cc index 408e1a0..250412d 100644 --- a/klotski/main.cc +++ b/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; } diff --git a/klotski/short_code.cc b/klotski/short_code.cc index 38985ba..b785796 100644 --- a/klotski/short_code.cc +++ b/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 +} diff --git a/klotski/short_code.h b/klotski/short_code.h index ee9ce49..1066992 100644 --- a/klotski/short_code.h +++ b/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 all_cases_list; // short_code -> common_code // std::unordered_map 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();