Browse Source

update: short code common search demo

legacy
Dnomd343 2 years ago
parent
commit
2981b02b13
  1. 2
      all_cases/all_cases.cc
  2. 5
      all_cases/all_cases.h
  3. 63
      all_cases/short_code.cc

2
all_cases/all_cases.cc

@ -11,7 +11,7 @@ inline uint32_t binary_count(uint32_t bin) { // get number of non-zero bits
return bin & 0b111111; return bin & 0b111111;
} }
inline uint32_t binary_reverse(uint32_t bin) { // reverse binary every 2-bits uint32_t AllCases::binary_reverse(uint32_t bin) { // reverse binary every 2-bits
bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF); bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF);
bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF); bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF);
bin = ((bin << 4) & 0xF0F0F0F0) | ((bin >> 4) & 0x0F0F0F0F); bin = ((bin << 4) & 0xF0F0F0F0) | ((bin >> 4) & 0x0F0F0F0F);

5
all_cases/all_cases.h

@ -12,8 +12,11 @@ public:
std::vector<uint32_t> all_cases[16]; std::vector<uint32_t> all_cases[16];
std::vector<uint32_t> basic_ranges; std::vector<uint32_t> basic_ranges;
static uint32_t binary_reverse(uint32_t bin);
static bool check_case(uint32_t head, uint32_t range);
private: private:
void load_basic_ranges(); void load_basic_ranges();
void generate_ranges(int n1, int n2, int n3, int n4); void generate_ranges(int n1, int n2, int n3, int n4);
static bool check_case(uint32_t head, uint32_t range); // static bool check_case(uint32_t head, uint32_t range);
}; };

63
all_cases/short_code.cc

@ -57,34 +57,55 @@ uint32_t code_from_string(const std::string &short_code) {
int main() { int main() {
auto a = AllCases(); auto a = AllCases();
a.find_all_cases();
std::vector<uint64_t> all_cases; // a.find_all_cases();
for (int n = 0; n < 16; ++n) { //
uint64_t prefix = (uint64_t)n << 32; // std::vector<uint64_t> all_cases;
for (auto &code : a.all_cases[n]) { // for (int n = 0; n < 16; ++n) {
all_cases.emplace_back(prefix | code); // uint64_t prefix = (uint64_t)n << 32;
} // for (auto &code : a.all_cases[n]) {
} // all_cases.emplace_back(prefix | code);
// }
// }
//
// std::unordered_map<uint64_t, uint32_t> all_cases_dict;
// for (int i = 0; i < all_cases.size(); ++i) {
// all_cases_dict[all_cases[i]] = i;
// }
std::unordered_map<uint64_t, uint32_t> all_cases_dict; uint32_t short_code = 14323231;
for (int i = 0; i < all_cases.size(); ++i) {
all_cases_dict[all_cases[i]] = i;
}
// uint32_t short_code = 14323231;
// printf("%09lX\n", all_cases[0]); // printf("%09lX\n", all_cases[0]);
// printf("%09lX\n", all_cases[short_code]); // printf("%09lX\n", all_cases[short_code]);
// printf("%09lX\n", all_cases[ALL_CASES_NUMBER - 1]); // printf("%09lX\n", all_cases[ALL_CASES_NUMBER - 1]);
std::cout << "start search" << std::endl; // std::cout << code_to_string(all_cases_dict[0x6EC0F8800]) << std::endl;
std::cout << code_to_string(all_cases_dict[0x6EC0F8800]) << std::endl; // std::cout << code_to_string(all_cases_dict[0x1A9BF0C00]) << std::endl;
std::cout << code_to_string(all_cases_dict[0x1A9BF0C00]) << std::endl; // std::cout << code_to_string(all_cases_dict[0x4FEA13400]) << std::endl;
std::cout << code_to_string(all_cases_dict[0x4FEA13400]) << std::endl;
// located code header
// 0 <= short_code < ALL_CASES_NUMBER
// printf("%d\n", all_cases_dict[0x6EC0F8800]); // uint32_t short_code = 5203298;
// printf("%d\n", all_cases_dict[0x1A9BF0C00]); int head = 0;
// printf("%d\n", all_cases_dict[0x4FEA13400]); for (; head < 16; ++head) {
if (short_code < ALL_CASES_SIZE[head]) {
break;
}
short_code -= ALL_CASES_SIZE[head];
}
std::cout << "head: " << head << std::endl;
std::cout << "sub short code: " << short_code << std::endl;
int index = 0;
for (auto &range : a.basic_ranges) {
if (AllCases::check_case(head, range)) {
if (index == short_code) {
printf("%08X\n", AllCases::binary_reverse(range));
break;
}
++index;
}
}
// std::cout << code_to_string(14323231) << std::endl; // std::cout << code_to_string(14323231) << std::endl;
// std::cout << code_from_string("8IzVj") << std::endl; // std::cout << code_from_string("8IzVj") << std::endl;

Loading…
Cancel
Save