|
@ -37,8 +37,8 @@ void FastCal::new_case(uint64_t code, uint64_t mask) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// build total search tree
|
|
|
/// build total search tree
|
|
|
void FastCal::build(const RawCode &code) { |
|
|
void FastCal::build() { |
|
|
auto core = init((uint64_t)code); |
|
|
auto core = init(root); |
|
|
/// start BFS search
|
|
|
/// start BFS search
|
|
|
while (!cache.empty()) { |
|
|
while (!cache.empty()) { |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
@ -47,8 +47,8 @@ void FastCal::build(const RawCode &code) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// found first matched target
|
|
|
/// found first matched target
|
|
|
RawCode FastCal::target(const RawCode &code, const match_t &match) { |
|
|
RawCode FastCal::target(const match_t &match) { |
|
|
auto core = init((uint64_t)code); |
|
|
auto core = init(root); |
|
|
/// start BFS search
|
|
|
/// start BFS search
|
|
|
while (!cache.empty()) { |
|
|
while (!cache.empty()) { |
|
|
if (match(cache.front()->code)) { |
|
|
if (match(cache.front()->code)) { |
|
@ -60,47 +60,47 @@ RawCode FastCal::target(const RawCode &code, const match_t &match) { |
|
|
return FC_NOT_FOUND; // target not found
|
|
|
return FC_NOT_FOUND; // target not found
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// found multi-targets matched in first same layer
|
|
|
/// found all of the furthest cases
|
|
|
std::vector<RawCode> FastCal::target_multi(const RawCode &code, const match_t &match) { |
|
|
std::vector<RawCode> FastCal::furthest() { |
|
|
auto core = init((uint64_t)code); |
|
|
auto core = init(root); |
|
|
auto layer_end = cache.back(); |
|
|
auto layer_end = cache.back(); |
|
|
std::vector<RawCode> matched; // matched list
|
|
|
std::vector<RawCode> layer_cases; |
|
|
/// start BFS search
|
|
|
/// start BFS search
|
|
|
while (!cache.empty()) { |
|
|
while (!cache.empty()) { |
|
|
if (match(cache.front()->code)) { // match target
|
|
|
|
|
|
matched.emplace_back(cache.front()->code); |
|
|
|
|
|
} |
|
|
|
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
|
|
|
layer_cases.emplace_back( |
|
|
|
|
|
RawCode::unsafe_create(cache.front()->code) // record layer cases
|
|
|
|
|
|
); |
|
|
if (cache.front() == layer_end) { // reach layer ending
|
|
|
if (cache.front() == layer_end) { // reach layer ending
|
|
|
if (!matched.empty()) { |
|
|
if (cache.size() == 1) { |
|
|
return matched; // stop at first matched layer
|
|
|
break; // stop loop at last layer
|
|
|
} |
|
|
} |
|
|
|
|
|
layer_cases.clear(); |
|
|
layer_end = cache.back(); // reset layer ending
|
|
|
layer_end = cache.back(); // reset layer ending
|
|
|
} |
|
|
} |
|
|
cache.pop(); |
|
|
cache.pop(); |
|
|
} |
|
|
} |
|
|
return std::vector<RawCode>{}; // no target found
|
|
|
return layer_cases; // release the latest layer cases
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// found all of the furthest cases
|
|
|
/// found multi-targets matched in first same layer
|
|
|
std::vector<RawCode> FastCal::furthest(const RawCode &code) { |
|
|
std::vector<RawCode> FastCal::target_multi(const FastCal::match_t &match) { |
|
|
auto core = init((uint64_t)code); |
|
|
auto core = init(root); |
|
|
auto layer_end = cache.back(); |
|
|
auto layer_end = cache.back(); |
|
|
std::vector<RawCode> layer_cases; |
|
|
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
|
|
|
|
|
|
matched.emplace_back(cache.front()->code); |
|
|
|
|
|
} |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
layer_cases.emplace_back( |
|
|
|
|
|
RawCode::unsafe_create(cache.front()->code) // record layer cases
|
|
|
|
|
|
); |
|
|
|
|
|
if (cache.front() == layer_end) { // reach layer ending
|
|
|
if (cache.front() == layer_end) { // reach layer ending
|
|
|
if (cache.size() == 1) { |
|
|
if (!matched.empty()) { |
|
|
break; // stop loop at last layer
|
|
|
return matched; // stop at first matched layer
|
|
|
} |
|
|
} |
|
|
layer_cases.clear(); |
|
|
|
|
|
layer_end = cache.back(); // reset layer ending
|
|
|
layer_end = cache.back(); // reset layer ending
|
|
|
} |
|
|
} |
|
|
cache.pop(); |
|
|
cache.pop(); |
|
|
} |
|
|
} |
|
|
return layer_cases; // release latest layer cases
|
|
|
return std::vector<RawCode>{}; // no target found
|
|
|
} |
|
|
} |
|
|