Browse Source

feat: layer data export

master
Dnomd343 2 years ago
parent
commit
e5427a8ffe
  1. 23
      src/analyse/analyse.cc
  2. 4
      src/analyse/analyse.h
  3. 20
      src/main.cc

23
src/analyse/analyse.cc

@ -8,6 +8,29 @@ void Analyse::set_root(const RawCode &code) {
this->root = (uint64_t)code;
}
std::vector<RawCode> Analyse::layer_export(uint32_t layer_num) {
std::vector<RawCode> layer_cases;
for (const auto &tmp : cases) { // traverse every cases
if (tmp.second.step == layer_num) {
layer_cases.emplace_back(RawCode::unsafe_create(tmp.first));
}
}
return layer_cases;
}
std::vector<std::vector<RawCode>> Analyse::layer_export() {
std::vector<std::vector<RawCode>> layer_cases;
for (const auto &tmp : cases) { // traverse every cases
if (tmp.second.step >= layer_cases.size()) {
layer_cases.resize(tmp.second.step + 1);
}
layer_cases[tmp.second.step].emplace_back(
RawCode::unsafe_create(tmp.first) // insert at target layer
);
}
return layer_cases;
}
/// memory initialize and return klotski core
Core Analyse::init(uint64_t code) {
/// reset working data

4
src/analyse/analyse.h

@ -22,6 +22,10 @@ public:
void build();
std::vector<RawCode> build_until(const match_t &match);
/// analysed layer export
std::vector<std::vector<RawCode>> layer_export();
std::vector<RawCode> layer_export(uint32_t layer_num);
private:
struct analyse_t {
uint64_t code;

20
src/main.cc

@ -41,7 +41,7 @@ int main() {
// sleep(3);
// std::cout << "start benchmark" << std::endl;
auto start_time = clock();
// auto start_time = clock();
// {
@ -54,21 +54,19 @@ int main() {
auto a = Analyse(RawCode::from_common_code("1a9bf0c"));
// a.build();
auto ret = a.build_until([](uint64_t code) {
return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
});
for (const auto &r : ret) {
std::cout << r << std::endl;
}
// auto ret = a.build_until((uint64_t)RawCode::from_common_code("1a9bf0c"), [](uint64_t code) {
a.build();
// auto ret = a.build_until([](uint64_t code) {
// return ((code >> (3 * 0xD)) & 0b111) == B_2x2;
// });
// for (const auto &r : ret) {
// std::cout << RawCode(r) << std::endl;
// std::cout << r << std::endl;
// }
auto start_time = clock();
std::cout << a.layer_export(81).size() << std::endl;
std::cout << a.layer_export()[81].size() << std::endl;
// auto raw_code = CommonCode("A5D3AF0").to_raw_code().unwrap();
// auto a = Analyse();

Loading…
Cancel
Save