Browse Source

feat: new namespace klotski

legacy
Dnomd343 2 years ago
parent
commit
8b67cbbb98
  1. 7
      src/klotski/all_cases/all_cases.cc
  2. 18
      src/klotski/all_cases/all_cases.h
  3. 2
      src/klotski/all_cases/basic_ranges.cc
  4. 15
      src/klotski/all_cases/basic_ranges.h
  5. 2
      src/klotski/common_code/common_code.cc
  6. 2
      src/klotski/ffi/tmain.cc
  7. 2
      src/klotski/raw_code/convert.cc
  8. 2
      src/klotski/short_code/convert.cc
  9. 2
      src/klotski/short_code/short_code.cc
  10. 2
      src/klotski/utils/common.cc
  11. 8
      src/klotski/utils/common.h

7
src/klotski/all_cases/all_cases.cc

@ -1,12 +1,7 @@
#include "common.h" #include "common.h"
#include "all_cases.h" #include "all_cases.h"
const uint32_t ALL_CASES_SIZE[16] = { using namespace klotski;
2942906, 2260392, 2942906, 0,
2322050, 1876945, 2322050, 0,
2322050, 1876945, 2322050, 0,
2942906, 2260392, 2942906, 0,
};
/// static variable initialize /// static variable initialize
std::mutex AllCases::building; std::mutex AllCases::building;

18
src/klotski/all_cases/all_cases.h

@ -5,16 +5,26 @@
#include <cstdint> #include <cstdint>
#include "basic_ranges.h" #include "basic_ranges.h"
class AllCases : public BasicRanges { namespace klotski {
public: /// 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,
};
class AllCases : public BasicRanges {
public:
static void build(); static void build();
static enum Status status(); static enum Status status();
static const std::vector<uint32_t> (&fetch())[16]; static const std::vector<uint32_t> (&fetch())[16];
private: private:
static bool available; static bool available;
static std::mutex building; static std::mutex building;
static std::vector<uint32_t> data[16]; static std::vector<uint32_t> data[16];
static void build_data(); static void build_data();
}; };
}

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"
const uint32_t BASIC_RANGES_SIZE = 7311921; using namespace klotski;
/// static variable initialize /// static variable initialize
std::mutex BasicRanges::building; std::mutex BasicRanges::building;

15
src/klotski/all_cases/basic_ranges.h

@ -4,8 +4,12 @@
#include <vector> #include <vector>
#include <cstdint> #include <cstdint>
class BasicRanges { namespace klotski {
public: /// basic ranges count
const uint32_t BASIC_RANGES_SIZE = 7311921;
class BasicRanges {
public:
enum Status { enum Status {
NO_INIT, NO_INIT,
BUILDING, BUILDING,
@ -13,9 +17,9 @@ public:
}; };
static void build(); static void build();
static enum Status status(); static enum Status status();
static const std::vector<uint32_t>& fetch(); static const std::vector<uint32_t> &fetch();
private: private:
struct generate_t { struct generate_t {
int n1; // number of `00` int n1; // number of `00`
int n2; // number of `01` int n2; // number of `01`
@ -29,4 +33,5 @@ private:
static void build_data(); static void build_data();
static void generate(generate_t info); static void generate(generate_t info);
}; };
}

2
src/klotski/common_code/common_code.cc

@ -2,6 +2,8 @@
#include "common.h" #include "common.h"
#include "common_code.h" #include "common_code.h"
using namespace klotski;
uint64_t CommonCode::unwrap() const { uint64_t CommonCode::unwrap() const {
return code; // raw uint64_t code return code; // raw uint64_t code
} }

2
src/klotski/ffi/tmain.cc

@ -14,7 +14,7 @@ void tmain() {
uint64_t common_code = 0x1A9BC0C00; uint64_t common_code = 0x1A9BC0C00;
Common::range_reverse(common_code); klotski::Common::range_reverse(common_code);
// uint64_t raw_code = 0x0603EDF5CAFFF5E2; // uint64_t raw_code = 0x0603EDF5CAFFF5E2;

2
src/klotski/raw_code/convert.cc

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

2
src/klotski/short_code/convert.cc

@ -6,6 +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;
/// 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
if (ShortCode::mode() == ShortCode::NORMAL) { if (ShortCode::mode() == ShortCode::NORMAL) {

2
src/klotski/short_code/short_code.cc

@ -1,6 +1,8 @@
#include "all_cases.h" #include "all_cases.h"
#include "short_code.h" #include "short_code.h"
using namespace klotski;
uint32_t ShortCode::unwrap() const { uint32_t ShortCode::unwrap() const {
return code; // raw uint32_t code return code; // raw uint32_t code
} }

2
src/klotski/utils/common.cc

@ -1,5 +1,7 @@
#include "common.h" #include "common.h"
using namespace klotski;
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);
bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF); bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF);

8
src/klotski/utils/common.h

@ -59,8 +59,10 @@
/// 00 01 10 11 ... => ... 11 10 01 00 /// 00 01 10 11 ... => ... 11 10 01 00
/// (high 8-bits) (low 8-bits) /// (high 8-bits) (low 8-bits)
class Common { namespace klotski {
public: class Common {
public:
static uint32_t range_reverse(uint32_t bin); static uint32_t range_reverse(uint32_t bin);
static uint8_t check_range(uint32_t head, uint32_t range); static uint8_t check_range(uint32_t head, uint32_t range);
}; };
}

Loading…
Cancel
Save