diff --git a/src/klotski/all_cases/all_cases.cc b/src/klotski/all_cases/all_cases.cc index 7f8e5b7..4a8bc78 100644 --- a/src/klotski/all_cases/all_cases.cc +++ b/src/klotski/all_cases/all_cases.cc @@ -1,12 +1,7 @@ #include "common.h" #include "all_cases.h" -const uint32_t ALL_CASES_SIZE[16] = { - 2942906, 2260392, 2942906, 0, - 2322050, 1876945, 2322050, 0, - 2322050, 1876945, 2322050, 0, - 2942906, 2260392, 2942906, 0, -}; +using namespace klotski; /// static variable initialize std::mutex AllCases::building; diff --git a/src/klotski/all_cases/all_cases.h b/src/klotski/all_cases/all_cases.h index 936a473..8e0fb0d 100644 --- a/src/klotski/all_cases/all_cases.h +++ b/src/klotski/all_cases/all_cases.h @@ -5,16 +5,26 @@ #include #include "basic_ranges.h" -class AllCases : public BasicRanges { -public: - static void build(); - static enum Status status(); - static const std::vector (&fetch())[16]; +namespace klotski { + /// all cases count + const uint32_t ALL_CASES_SIZE[16] = { + 2942906, 2260392, 2942906, 0, + 2322050, 1876945, 2322050, 0, + 2322050, 1876945, 2322050, 0, + 2942906, 2260392, 2942906, 0, + }; -private: - static bool available; - static std::mutex building; - static std::vector data[16]; + class AllCases : public BasicRanges { + public: + static void build(); + static enum Status status(); + static const std::vector (&fetch())[16]; - static void build_data(); -}; + private: + static bool available; + static std::mutex building; + static std::vector data[16]; + + static void build_data(); + }; +} diff --git a/src/klotski/all_cases/basic_ranges.cc b/src/klotski/all_cases/basic_ranges.cc index eed55b1..d9c7608 100644 --- a/src/klotski/all_cases/basic_ranges.cc +++ b/src/klotski/all_cases/basic_ranges.cc @@ -3,7 +3,7 @@ #include "common.h" #include "basic_ranges.h" -const uint32_t BASIC_RANGES_SIZE = 7311921; +using namespace klotski; /// static variable initialize std::mutex BasicRanges::building; diff --git a/src/klotski/all_cases/basic_ranges.h b/src/klotski/all_cases/basic_ranges.h index 2b86c89..6c03aaf 100644 --- a/src/klotski/all_cases/basic_ranges.h +++ b/src/klotski/all_cases/basic_ranges.h @@ -4,29 +4,34 @@ #include #include -class BasicRanges { -public: - enum Status { - NO_INIT, - BUILDING, - AVAILABLE, - }; - static void build(); - static enum Status status(); - static const std::vector& fetch(); +namespace klotski { + /// basic ranges count + const uint32_t BASIC_RANGES_SIZE = 7311921; -private: - struct generate_t { - int n1; // number of `00` - int n2; // number of `01` - int n3; // number of `10` - int n4; // number of `11` - }; + class BasicRanges { + public: + enum Status { + NO_INIT, + BUILDING, + AVAILABLE, + }; + static void build(); + static enum Status status(); + static const std::vector &fetch(); - static bool available; - static std::mutex building; - static std::vector data; + private: + struct generate_t { + int n1; // number of `00` + int n2; // number of `01` + int n3; // number of `10` + int n4; // number of `11` + }; - static void build_data(); - static void generate(generate_t info); -}; + static bool available; + static std::mutex building; + static std::vector data; + + static void build_data(); + static void generate(generate_t info); + }; +} diff --git a/src/klotski/common_code/common_code.cc b/src/klotski/common_code/common_code.cc index 3a3101e..14d6771 100644 --- a/src/klotski/common_code/common_code.cc +++ b/src/klotski/common_code/common_code.cc @@ -2,6 +2,8 @@ #include "common.h" #include "common_code.h" +using namespace klotski; + uint64_t CommonCode::unwrap() const { return code; // raw uint64_t code } diff --git a/src/klotski/ffi/tmain.cc b/src/klotski/ffi/tmain.cc index ee69004..1b0b65e 100644 --- a/src/klotski/ffi/tmain.cc +++ b/src/klotski/ffi/tmain.cc @@ -14,7 +14,7 @@ void tmain() { uint64_t common_code = 0x1A9BC0C00; - Common::range_reverse(common_code); + klotski::Common::range_reverse(common_code); // uint64_t raw_code = 0x0603EDF5CAFFF5E2; diff --git a/src/klotski/raw_code/convert.cc b/src/klotski/raw_code/convert.cc index a361b78..ee3ff55 100644 --- a/src/klotski/raw_code/convert.cc +++ b/src/klotski/raw_code/convert.cc @@ -2,6 +2,8 @@ #include "common.h" #include "raw_code.h" +using namespace klotski; + /// RawCode to CommonCode CommonCode RawCode::to_common_code() const { if (!RawCode::check(code)) { diff --git a/src/klotski/short_code/convert.cc b/src/klotski/short_code/convert.cc index c90dca0..ed6306d 100644 --- a/src/klotski/short_code/convert.cc +++ b/src/klotski/short_code/convert.cc @@ -6,6 +6,8 @@ #include "basic_ranges_offset.h" #include "range_prefix_offset.h" +using namespace klotski; + /// ShortCode to CommonCode CommonCode ShortCode::to_common_code() const { // convert to common code if (ShortCode::mode() == ShortCode::NORMAL) { diff --git a/src/klotski/short_code/short_code.cc b/src/klotski/short_code/short_code.cc index 6bdb385..397a331 100644 --- a/src/klotski/short_code/short_code.cc +++ b/src/klotski/short_code/short_code.cc @@ -1,6 +1,8 @@ #include "all_cases.h" #include "short_code.h" +using namespace klotski; + uint32_t ShortCode::unwrap() const { return code; // raw uint32_t code } diff --git a/src/klotski/utils/common.cc b/src/klotski/utils/common.cc index 6c12042..9535140 100644 --- a/src/klotski/utils/common.cc +++ b/src/klotski/utils/common.cc @@ -1,5 +1,7 @@ #include "common.h" +using namespace klotski; + uint32_t Common::range_reverse(uint32_t bin) { // reverse binary every 2-bits bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF); bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF); diff --git a/src/klotski/utils/common.h b/src/klotski/utils/common.h index 5b4006d..b103572 100644 --- a/src/klotski/utils/common.h +++ b/src/klotski/utils/common.h @@ -59,8 +59,10 @@ /// 00 01 10 11 ... => ... 11 10 01 00 /// (high 8-bits) (low 8-bits) -class Common { -public: - static uint32_t range_reverse(uint32_t bin); - static uint8_t check_range(uint32_t head, uint32_t range); -}; +namespace klotski { + class Common { + public: + static uint32_t range_reverse(uint32_t bin); + static uint8_t check_range(uint32_t head, uint32_t range); + }; +}