|
@ -39,24 +39,26 @@ void FastCal::new_case(uint64_t code, uint64_t mask) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// found first matched target
|
|
|
/// found first matched target
|
|
|
uint64_t FastCal::target(uint64_t code, const check_t &match) { |
|
|
RawCode FastCal::target(RawCode code, const check_t &match) { |
|
|
auto core = init(code); |
|
|
auto core = init((uint64_t)code); |
|
|
while (!cache.empty()) { // bfs search
|
|
|
/// start bfs search
|
|
|
|
|
|
while (!cache.empty()) { |
|
|
if (match(cache.front()->code)) { |
|
|
if (match(cache.front()->code)) { |
|
|
return cache.front()->code; // match target
|
|
|
return RawCode::unsafe_create(cache.front()->code); // match target
|
|
|
} |
|
|
} |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
cache.pop(); |
|
|
cache.pop(); |
|
|
} |
|
|
} |
|
|
return FastCal::NOT_FOUND; // target not found
|
|
|
return FC_NOT_FOUND; // target not found
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// found multi-targets matched in first same layer
|
|
|
/// found multi-targets matched in first same layer
|
|
|
std::vector<uint64_t> FastCal::target_multi(uint64_t code, const check_t &match) { |
|
|
std::vector<RawCode> FastCal::target_multi(RawCode code, const check_t &match) { |
|
|
auto core = init(code); |
|
|
auto core = init((uint64_t)code); |
|
|
auto layer_end = cache.back(); |
|
|
auto layer_end = cache.back(); |
|
|
std::vector<uint64_t> matched; // matched list
|
|
|
std::vector<RawCode> matched; // matched list
|
|
|
while (!cache.empty()) { // bfs search
|
|
|
/// start bfs search
|
|
|
|
|
|
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(cache.front()->code); |
|
|
} |
|
|
} |
|
@ -69,17 +71,20 @@ std::vector<uint64_t> FastCal::target_multi(uint64_t code, const check_t &match) |
|
|
} |
|
|
} |
|
|
cache.pop(); |
|
|
cache.pop(); |
|
|
} |
|
|
} |
|
|
return std::vector<uint64_t>{}; // no target found
|
|
|
return std::vector<RawCode>{}; // no target found
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// found all of the furthest cases
|
|
|
/// found all of the furthest cases
|
|
|
std::vector<uint64_t> FastCal::furthest(uint64_t code) { |
|
|
std::vector<RawCode> FastCal::furthest(RawCode code) { |
|
|
auto core = init(code); |
|
|
auto core = init((uint64_t)code); |
|
|
auto layer_end = cache.back(); |
|
|
auto layer_end = cache.back(); |
|
|
std::vector<uint64_t> layer_cases; |
|
|
std::vector<RawCode> layer_cases; |
|
|
while (!cache.empty()) { // bfs search
|
|
|
/// start bfs search
|
|
|
|
|
|
while (!cache.empty()) { |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
core.next_cases(cache.front()->code, cache.front()->mask); |
|
|
layer_cases.emplace_back(cache.front()->code); // record layer cases
|
|
|
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 (cache.size() == 1) { |
|
|
break; // stop loop at last layer
|
|
|
break; // stop loop at last layer
|
|
|