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