Browse Source

update: AllCases release with CommonCode

master
Dnomd343 2 years ago
parent
commit
b41f73da6e
  1. 4
      src/klotski_core/all_cases/all_cases.cc
  2. 10
      src/klotski_core/all_cases/all_cases.h
  3. 2
      src/klotski_core/short_code/short_code.h
  4. 5
      test/basic/all_cases.cc
  5. 7
      test/codec/short_code.cc

4
src/klotski_core/all_cases/all_cases.cc

@ -41,8 +41,8 @@ void AllCases::build() { // ensure that data is available
}
}
std::vector<uint64_t> AllCases::release() {
std::vector<uint64_t> data;
std::vector<CommonCode> AllCases::release() {
std::vector<CommonCode> data;
data.reserve(ALL_CASES_SIZE_SUM); // memory pre-allocated
for (uint64_t head = 0; head < 16; ++head) {
for (const auto &range : fetch()[head]) {

10
src/klotski_core/all_cases/all_cases.h

@ -21,10 +21,13 @@
#include <vector>
#include <cstdint>
#include <numeric>
#include "common_code.h"
#include "basic_ranges.h"
namespace klotski {
class CommonCode;
/// all cases count
const uint32_t ALL_CASES_SIZE[16] = {
2942906, 2260392, 2942906, 0,
@ -32,9 +35,8 @@ const uint32_t ALL_CASES_SIZE[16] = {
2322050, 1876945, 2322050, 0,
2942906, 2260392, 2942906, 0,
};
const uint32_t ALL_CASES_SIZE_SUM = std::accumulate( // aka 29334498
ALL_CASES_SIZE, ALL_CASES_SIZE + 16, (uint32_t)0
);
const uint32_t ALL_CASES_SIZE_SUM = 29334498;
class AllCases : public BasicRanges {
public:
@ -48,7 +50,7 @@ public:
static const std::vector<uint32_t> (&fetch())[16];
/// Export all possible common codes.
static std::vector<uint64_t> release();
static std::vector<CommonCode> release();
private:
static bool available_;

2
src/klotski_core/short_code/short_code.h

@ -60,7 +60,7 @@ namespace klotski {
class CommonCode;
const uint32_t SHORT_CODE_LIMIT = klotski::ALL_CASES_SIZE_SUM;
const uint32_t SHORT_CODE_LIMIT = 29334498;
class ShortCodeException : public std::runtime_error {
public:

5
test/basic/all_cases.cc

@ -70,6 +70,9 @@ TEST(AllCases, all_cases_size) {
for (uint32_t head = 0; head < 16; ++head) {
EXPECT_EQ(all_cases[head].size(), ALL_CASES_SIZE[head]);
}
EXPECT_EQ(
std::accumulate(ALL_CASES_SIZE, ALL_CASES_SIZE + 16, (uint32_t)0), ALL_CASES_SIZE_SUM
);
}
/// all cases data verify
@ -92,7 +95,7 @@ TEST(AllCases, all_cases_release) {
auto current = release.begin();
for (uint64_t head = 0; head < 16; ++head) {
for (const auto &range : AllCases::fetch()[head]) {
EXPECT_EQ(*current, head << 32 | range);
EXPECT_EQ(current->unwrap(), head << 32 | range);
++current;
}
}

7
test/codec/short_code.cc

@ -10,6 +10,9 @@ using klotski::ShortCode;
using klotski::CommonCode;
using klotski::BasicRanges;
using klotski::SHORT_CODE_LIMIT;
using klotski::ALL_CASES_SIZE_SUM;
const static uint32_t TEST_CODE = 4091296;
const static std::string TEST_CODE_STR = "4WVE1";
@ -23,6 +26,10 @@ static inline void SHOULD_PANIC(const std::function<void()> &func) {
EXPECT_EQ(panic_flag, true);
}
TEST(ShortCode, limit) {
EXPECT_EQ(ALL_CASES_SIZE_SUM, SHORT_CODE_LIMIT);
}
TEST(ShortCode, hash) {
auto tmp = std::unordered_set<ShortCode>{ ShortCode(TEST_CODE) };
EXPECT_EQ(tmp.size(), 1);

Loading…
Cancel
Save