|
@ -1,6 +1,14 @@ |
|
|
#include <queue> |
|
|
|
|
|
#include "analyse.h" |
|
|
#include "analyse.h" |
|
|
|
|
|
|
|
|
|
|
|
Analyse::Analyse(const RawCode &code) { |
|
|
|
|
|
this->root = (uint64_t)code; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Analyse::set_root(const RawCode &code) { |
|
|
|
|
|
this->root = (uint64_t)code; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// memory initialize and return klotski core
|
|
|
Core Analyse::init(uint64_t code) { |
|
|
Core Analyse::init(uint64_t code) { |
|
|
/// reset working data
|
|
|
/// reset working data
|
|
|
cases.clear(); |
|
|
cases.clear(); |
|
@ -41,22 +49,25 @@ void Analyse::new_case(uint64_t code, uint64_t mask) { |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void Analyse::build(uint64_t code) { |
|
|
/// analyse and build klotski tree
|
|
|
auto core = init(code); |
|
|
void Analyse::build() { |
|
|
|
|
|
auto core = init(root); |
|
|
while (!cache.empty()) { |
|
|
while (!cache.empty()) { |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
cache.pop(); |
|
|
cache.pop(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
std::vector<uint64_t> Analyse::build_until(uint64_t code, const match_t &match) { |
|
|
std::vector<RawCode> Analyse::build_until(const match_t &match) { |
|
|
auto core = init(code); |
|
|
auto core = init(root); |
|
|
auto layer_end = cache.back(); |
|
|
auto layer_end = cache.back(); |
|
|
std::vector<uint64_t> matched; // matched list
|
|
|
std::vector<RawCode> matched; // matched list
|
|
|
/// start BFS search
|
|
|
/// start BFS search
|
|
|
while (!cache.empty()) { |
|
|
while (!cache.empty()) { |
|
|
if (match(cache.front()->code)) { // match target
|
|
|
if (match(cache.front()->code)) { // match target
|
|
|
matched.emplace_back(cache.front()->code); |
|
|
matched.emplace_back( |
|
|
|
|
|
RawCode::unsafe_create(cache.front()->code) // record matched cases
|
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
if (cache.front() == layer_end) { // reach layer ending
|
|
|
if (cache.front() == layer_end) { // reach layer ending
|
|
@ -67,5 +78,5 @@ std::vector<uint64_t> Analyse::build_until(uint64_t code, const match_t &match) |
|
|
} |
|
|
} |
|
|
cache.pop(); |
|
|
cache.pop(); |
|
|
} |
|
|
} |
|
|
return std::vector<uint64_t>{}; // no target found
|
|
|
return std::vector<RawCode>{}; // no target found
|
|
|
} |
|
|
} |
|
|