Browse Source

update: check code before zip and unzip

legacy
Dnomd343 2 years ago
parent
commit
566a90ded5
  1. 9
      klotski/main.cc
  2. 15
      klotski/short_code.cc

9
klotski/main.cc

@ -46,12 +46,9 @@ int main() {
// std::cout << s.zip_short_code(0x6EC0F8800) << std::endl;
// std::cout << "complete" << std::endl;
// if (ShortCode::check(14323231)) {
if (ShortCode::check(87654321)) {
std::cout << "true" << std::endl;
} else {
std::cout << "false" << std::endl;
}
printf("%d\n", s.zip_short_code(0x6EC0F8800));
printf("%09lX\n", s.unzip_short_code(14323231));
// printf("%09lX\n", s.unzip_short_code(87654321));
return 0;
}

15
klotski/short_code.cc

@ -3,6 +3,7 @@
#include "all_cases.h"
#include "short_code.h"
#include "short_code_mark.h"
#include "common_code.h"
ShortCode::ShortCode(ShortCode::Mode mode) { // class initialize
speed_up(mode);
@ -106,9 +107,9 @@ uint32_t ShortCode::tiny_encode(uint64_t common_code) {
}
uint32_t ShortCode::zip_short_code(uint64_t common_code) { // common_code --zip--> short_code
// TODO: confirm common_code valid
if (!CommonCode::check(common_code)) {
throw std::runtime_error("invalid common code");
}
switch (check_mode()) {
case ShortCode::Mode::NORMAL:
return tiny_encode(common_code);
@ -120,11 +121,9 @@ uint32_t ShortCode::zip_short_code(uint64_t common_code) { // common_code --zip-
}
uint64_t ShortCode::unzip_short_code(uint32_t short_code) { // short_code --unzip--> common_code
// TODO: confirm short_code valid
if (!check(short_code)) {
throw std::runtime_error("invalid short code");
}
switch (check_mode()) {
case ShortCode::Mode::NORMAL:
return tiny_decode(short_code);

Loading…
Cancel
Save