Browse Source

chore: code modules using namespace klotski

master
Dnomd343 2 years ago
parent
commit
3f0569d6f9
  1. 2
      src/klotski/all_cases/all_cases.cc
  2. 2
      src/klotski/all_cases/basic_ranges.cc
  3. 3
      src/klotski/analyse/analyse.h
  4. 4
      src/klotski/common_code/common_code.cc
  5. 3
      src/klotski/common_code/common_code.h
  6. 4
      src/klotski/common_code/convert.cc
  7. 2
      src/klotski/common_code/serialize.cc
  8. 3
      src/klotski/fast_cal/fast_cal.h
  9. 2
      src/klotski/ffi/codec.cc
  10. 3
      src/klotski/raw_code/convert.cc
  11. 4
      src/klotski/raw_code/raw_code.cc
  12. 3
      src/klotski/raw_code/raw_code.h
  13. 3
      src/klotski/short_code/convert.cc
  14. 2
      src/klotski/short_code/serialize.cc
  15. 2
      src/klotski/short_code/serialize_chars.h
  16. 4
      src/klotski/short_code/short_code.cc
  17. 6
      src/klotski/short_code/short_code.h
  18. 2
      src/klotski/utils/common.cc
  19. 5
      test/all_cases.cc
  20. 2
      test/utils.cc

2
src/klotski/all_cases/all_cases.cc

@ -1,7 +1,7 @@
#include "common.h" #include "common.h"
#include "all_cases.h" #include "all_cases.h"
using namespace klotski; using klotski::AllCases;
/// static variable initialize /// static variable initialize
std::mutex AllCases::building; std::mutex AllCases::building;

2
src/klotski/all_cases/basic_ranges.cc

@ -3,7 +3,7 @@
#include "common.h" #include "common.h"
#include "basic_ranges.h" #include "basic_ranges.h"
using namespace klotski; using klotski::BasicRanges;
/// static variable initialize /// static variable initialize
std::mutex BasicRanges::building; std::mutex BasicRanges::building;

3
src/klotski/analyse/analyse.h

@ -11,6 +11,9 @@
// TODO: try double or 4-times size // TODO: try double or 4-times size
const uint32_t ANY_MAP_RESERVE = 65536; const uint32_t ANY_MAP_RESERVE = 65536;
// TODO: Analyse enter klotski namespace later
using namespace klotski;
class Analyse { class Analyse {
public: public:
typedef std::function<bool(uint64_t)> match_t; typedef std::function<bool(uint64_t)> match_t;

4
src/klotski/common_code/common_code.cc

@ -2,7 +2,7 @@
#include "common.h" #include "common.h"
#include "common_code.h" #include "common_code.h"
using namespace klotski; using klotski::CommonCode;
uint64_t CommonCode::unwrap() const { uint64_t CommonCode::unwrap() const {
return code; // raw uint64_t code return code; // raw uint64_t code
@ -33,12 +33,14 @@ bool CommonCode::operator==(const CommonCode &common_code) const {
return this->code == common_code.code; return this->code == common_code.code;
} }
namespace klotski {
std::ostream &operator<<(std::ostream &out, const CommonCode &self) { std::ostream &operator<<(std::ostream &out, const CommonCode &self) {
char str[10]; char str[10];
sprintf(str, "%09lX", self.code); sprintf(str, "%09lX", self.code);
out << str; out << str;
return out; return out;
} }
}
bool CommonCode::check(uint64_t common_code) { // whether common code is valid bool CommonCode::check(uint64_t common_code) { // whether common code is valid
/// M_1x1 M_1x2 M_2x1 M_2x2 /// M_1x1 M_1x2 M_2x1 M_2x2

3
src/klotski/common_code/common_code.h

@ -6,6 +6,8 @@
#include "raw_code.h" #include "raw_code.h"
#include "short_code.h" #include "short_code.h"
namespace klotski {
/// import for convert interface
class RawCode; class RawCode;
class ShortCode; class ShortCode;
@ -47,3 +49,4 @@ private:
uint64_t code; uint64_t code;
CommonCode() = default; // unsafe initialize CommonCode() = default; // unsafe initialize
}; };
}

4
src/klotski/common_code/convert.cc

@ -1,5 +1,9 @@
#include "common_code.h" #include "common_code.h"
using klotski::RawCode;
using klotski::ShortCode;
using klotski::CommonCode;
/// CommonCode to RawCode /// CommonCode to RawCode
RawCode CommonCode::to_raw_code() const { RawCode CommonCode::to_raw_code() const {
return RawCode(*this); // convert to raw code return RawCode(*this); // convert to raw code

2
src/klotski/common_code/serialize.cc

@ -1,5 +1,7 @@
#include "common_code.h" #include "common_code.h"
using klotski::CommonCode;
inline uint8_t binary_count(uint32_t bin) { // get number of non-zero bits inline uint8_t binary_count(uint32_t bin) { // get number of non-zero bits
bin -= (bin >> 1) & 0x55555555; bin -= (bin >> 1) & 0x55555555;
bin = (bin & 0x33333333) + ((bin >> 2) & 0x33333333); bin = (bin & 0x33333333) + ((bin >> 2) & 0x33333333);

3
src/klotski/fast_cal/fast_cal.h

@ -8,6 +8,9 @@
#include "core.h" #include "core.h"
#include "raw_code.h" #include "raw_code.h"
// TODO: FastCal enter klotski namespace later
using namespace klotski;
// TODO: using prime number // TODO: using prime number
const uint32_t FC_MAP_RESERVE = 65536 * 8; const uint32_t FC_MAP_RESERVE = 65536 * 8;

2
src/klotski/ffi/codec.cc

@ -1,6 +1,8 @@
#include "klotski.h" #include "klotski.h"
#include "short_code.h" #include "short_code.h"
using klotski::ShortCode;
void short_code_speed_up() { void short_code_speed_up() {
ShortCode::speed_up(ShortCode::NORMAL); ShortCode::speed_up(ShortCode::NORMAL);
} }

3
src/klotski/raw_code/convert.cc

@ -2,7 +2,8 @@
#include "common.h" #include "common.h"
#include "raw_code.h" #include "raw_code.h"
using namespace klotski; using klotski::RawCode;
using klotski::CommonCode;
/// RawCode to CommonCode /// RawCode to CommonCode
CommonCode RawCode::to_common_code() const { CommonCode RawCode::to_common_code() const {

4
src/klotski/raw_code/raw_code.cc

@ -2,6 +2,8 @@
#include "common.h" #include "common.h"
#include "raw_code.h" #include "raw_code.h"
using klotski::RawCode;
uint64_t RawCode::unwrap() const { uint64_t RawCode::unwrap() const {
return code; // raw uint64_t code return code; // raw uint64_t code
} }
@ -31,6 +33,7 @@ bool RawCode::operator==(const RawCode &raw_code) const {
return this->code == raw_code.code; return this->code == raw_code.code;
} }
namespace klotski {
std::ostream &operator<<(std::ostream &out, const RawCode &self) { std::ostream &operator<<(std::ostream &out, const RawCode &self) {
char code[16]; char code[16];
char dump_map[] = { char dump_map[] = {
@ -45,6 +48,7 @@ std::ostream& operator<<(std::ostream &out, const RawCode &self) {
} }
return out; return out;
} }
}
bool RawCode::check(uint64_t raw_code) { // check whether raw code is valid bool RawCode::check(uint64_t raw_code) { // check whether raw code is valid
/// MASK_1x2 MASK_2x1 MASK_2x2 /// MASK_1x2 MASK_2x1 MASK_2x2

3
src/klotski/raw_code/raw_code.h

@ -39,6 +39,8 @@
#include <ostream> #include <ostream>
#include "common_code.h" #include "common_code.h"
namespace klotski {
/// import for convert interface
class CommonCode; class CommonCode;
class RawCode { class RawCode {
@ -76,3 +78,4 @@ private:
static uint64_t compact(uint64_t raw_code); static uint64_t compact(uint64_t raw_code);
static uint64_t extract(uint64_t common_code); static uint64_t extract(uint64_t common_code);
}; };
}

3
src/klotski/short_code/convert.cc

@ -6,7 +6,8 @@
#include "basic_ranges_offset.h" #include "basic_ranges_offset.h"
#include "range_prefix_offset.h" #include "range_prefix_offset.h"
using namespace klotski; using klotski::ShortCode;
using klotski::CommonCode;
/// ShortCode to CommonCode /// ShortCode to CommonCode
CommonCode ShortCode::to_common_code() const { // convert to common code CommonCode ShortCode::to_common_code() const { // convert to common code

2
src/klotski/short_code/serialize.cc

@ -2,6 +2,8 @@
#include "short_code.h" #include "short_code.h"
#include "serialize_chars.h" #include "serialize_chars.h"
using klotski::ShortCode;
ShortCode ShortCode::from_string(const std::string &short_code) { ShortCode ShortCode::from_string(const std::string &short_code) {
return ShortCode(short_code); // convert from string return ShortCode(short_code); // convert from string
} }

2
src/klotski/short_code/serialize_chars.h

@ -2,6 +2,7 @@
#include <cstdint> #include <cstdint>
namespace klotski {
const int8_t SHORT_CODE_TABLE[32] = { const int8_t SHORT_CODE_TABLE[32] = {
'1', '2', '3', '4', '5', '6', '7', '8', '9', // skip `0` '1', '2', '3', '4', '5', '6', '7', '8', '9', // skip `0`
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // skip `I` 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', // skip `I`
@ -18,3 +19,4 @@ const int8_t SHORT_CODE_TABLE_REV[42] = {
18, -1, 19, 20, -1, 21, 22, 23, 24, 25, // `K`(75) ~ `T`(84) 18, -1, 19, 20, -1, 21, 22, 23, 24, 25, // `K`(75) ~ `T`(84)
26, 27, 28, 29, 30, 31, // `U`(85) ~ `Z`(90) 26, 27, 28, 29, 30, 31, // `U`(85) ~ `Z`(90)
}; };
}

4
src/klotski/short_code/short_code.cc

@ -1,7 +1,7 @@
#include "all_cases.h" #include "all_cases.h"
#include "short_code.h" #include "short_code.h"
using namespace klotski; using klotski::ShortCode;
uint32_t ShortCode::unwrap() const { uint32_t ShortCode::unwrap() const {
return code; // raw uint32_t code return code; // raw uint32_t code
@ -30,10 +30,12 @@ bool ShortCode::operator==(const ShortCode &short_code) const {
return this->code == short_code.code; return this->code == short_code.code;
} }
namespace klotski {
std::ostream &operator<<(std::ostream &out, const ShortCode &self) { std::ostream &operator<<(std::ostream &out, const ShortCode &self) {
out << self.to_string() << "(" << self.code << ")"; // short code info out << self.to_string() << "(" << self.code << ")"; // short code info
return out; return out;
} }
}
bool ShortCode::fast_mode_available = false; bool ShortCode::fast_mode_available = false;
bool ShortCode::normal_mode_available = false; bool ShortCode::normal_mode_available = false;

6
src/klotski/short_code/short_code.h

@ -5,8 +5,8 @@
#include <ostream> #include <ostream>
#include "common_code.h" #include "common_code.h"
const uint32_t SHORT_CODE_LIMIT = 29334498; namespace klotski {
/// import for convert interface
class CommonCode; class CommonCode;
class ShortCode { class ShortCode {
@ -48,6 +48,7 @@ private:
uint32_t code; uint32_t code;
static bool fast_mode_available; static bool fast_mode_available;
static bool normal_mode_available; static bool normal_mode_available;
static const uint32_t SHORT_CODE_LIMIT = 29334498;
static enum Mode mode(); static enum Mode mode();
static uint64_t fast_decode(uint32_t short_code); static uint64_t fast_decode(uint32_t short_code);
@ -55,3 +56,4 @@ private:
static uint64_t tiny_decode(uint32_t short_code); static uint64_t tiny_decode(uint32_t short_code);
static uint32_t tiny_encode(uint64_t common_code); static uint32_t tiny_encode(uint64_t common_code);
}; };
}

2
src/klotski/utils/common.cc

@ -1,6 +1,6 @@
#include "common.h" #include "common.h"
using namespace klotski; using klotski::Common;
uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits
bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF); bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF);

5
test/all_cases.cc

@ -3,7 +3,10 @@
#include "all_cases.h" #include "all_cases.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace klotski; using klotski::AllCases;
using klotski::BasicRanges;
using klotski::ALL_CASES_SIZE;
using klotski::BASIC_RANGES_SIZE;
/// basic ranges constants /// basic ranges constants
const char BASIC_RANGES_MD5[] = "6f385dc171e201089ff96bb010b47212"; const char BASIC_RANGES_MD5[] = "6f385dc171e201089ff96bb010b47212";

2
test/utils.cc

@ -2,7 +2,7 @@
#include "common.h" #include "common.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
using namespace klotski; using klotski::Common;
TEST(Utils, range_reverse) { TEST(Utils, range_reverse) {
EXPECT_EQ(Common::range_reverse((uint32_t)0x00000003), (uint32_t)0xC0000000); EXPECT_EQ(Common::range_reverse((uint32_t)0x00000003), (uint32_t)0xC0000000);

Loading…
Cancel
Save