mirror of https://github.com/dnomd343/klotski.git
Dnomd343
2 years ago
5 changed files with 70 additions and 9 deletions
@ -1,4 +1,4 @@ |
|||
cmake_minimum_required(VERSION 3.0) |
|||
set(CMAKE_CXX_STANDARD 14) |
|||
|
|||
add_executable(klotski main.cc common.cc all_cases.cc) |
|||
add_executable(klotski main.cc common.cc all_cases.cc short_code.cc) |
|||
|
@ -1,20 +1,31 @@ |
|||
#include <iostream> |
|||
#include "all_cases.h" |
|||
//#include "all_cases.h"
|
|||
#include "short_code.h" |
|||
|
|||
int main() { |
|||
|
|||
// auto a = AllCases();
|
|||
// auto a = AllCases(AllCases::InitType::WITH_NOTHING);
|
|||
// auto a = AllCases(AllCases::InitType::WITH_BASIC_RANGES);
|
|||
auto a = AllCases(AllCases::InitType::WITH_ALL_CASES); |
|||
// auto a = AllCases(AllCases::InitType::WITH_ALL_CASES);
|
|||
|
|||
std::cout << "start get basic ranges" << std::endl; |
|||
std::cout << "basic range: " << a.get_basic_ranges()->size() << std::endl; |
|||
// std::cout << "start get basic ranges" << std::endl;
|
|||
// std::cout << "basic range: " << a.get_basic_ranges()->size() << std::endl;
|
|||
|
|||
std::cout << "start get all cases" << std::endl; |
|||
for (const auto &temp : *a.get_all_cases()) { |
|||
std::cout << temp.size() << std::endl; |
|||
} |
|||
// std::cout << "start get all cases" << std::endl;
|
|||
// for (const auto &temp : *a.get_all_cases()) {
|
|||
// std::cout << temp.size() << std::endl;
|
|||
// }
|
|||
|
|||
auto s = ShortCode(); |
|||
|
|||
s.speed_up(); |
|||
std::cout << s.all_cases_list.size() << std::endl; |
|||
std::cout << s.all_cases_dict.size() << std::endl; |
|||
|
|||
// s.speed_up();
|
|||
// std::cout << s.all_cases_list.size() << std::endl;
|
|||
// std::cout << s.all_cases_dict.size() << std::endl;
|
|||
|
|||
return 0; |
|||
} |
|||
|
@ -0,0 +1,27 @@ |
|||
#include "all_cases.h" |
|||
#include "short_code.h" |
|||
#include "short_code_mark.h" |
|||
|
|||
//#include <iostream>
|
|||
|
|||
void ShortCode::build_mapping() { // build fast search mapping
|
|||
auto all = AllCases(AllCases::InitType::WITH_ALL_CASES); |
|||
// std::cout << "start build" << std::endl;
|
|||
for (int head = 0; head < 16; ++head) { |
|||
uint64_t prefix = (uint64_t)head << 32; |
|||
for (const auto &range : (*all.get_all_cases())[head]) { |
|||
all_cases_list.emplace_back(prefix | range); // short_code => common_code
|
|||
} |
|||
} |
|||
// std::cout << "stage-1 ok" << std::endl;
|
|||
for (int n = 0; n < all_cases_list.size(); ++n) { |
|||
all_cases_dict[all_cases_list[n]] = n; // common_code => short_code
|
|||
} |
|||
// std::cout << "complete build" << std::endl;
|
|||
} |
|||
|
|||
void ShortCode::speed_up() { |
|||
if (all_cases_list.empty()) { |
|||
build_mapping(); |
|||
} |
|||
} |
@ -0,0 +1,23 @@ |
|||
#pragma once |
|||
|
|||
#include <vector> |
|||
#include <cstdint> |
|||
#include <unordered_map> |
|||
|
|||
class ShortCode { |
|||
public: |
|||
|
|||
std::vector<uint64_t> all_cases_list; // short_code -> common_code
|
|||
std::unordered_map<uint64_t, uint32_t> all_cases_dict; // common_code -> short_code
|
|||
|
|||
void speed_up(); |
|||
|
|||
|
|||
private: |
|||
// std::vector<uint64_t> all_cases_list; // short_code -> common_code
|
|||
// std::unordered_map<uint64_t, uint32_t> all_cases_dict; // common_code -> short_code
|
|||
|
|||
void build_mapping(); |
|||
|
|||
|
|||
}; |
Loading…
Reference in new issue