From 672c89556fc8ed1c1928837f60a7772375577b1d Mon Sep 17 00:00:00 2001 From: Dnomd343 Date: Fri, 6 Jan 2023 11:27:38 +0800 Subject: [PATCH] remove: legacy code --- all_cases/all_cases.cc | 145 ------------------------------------ all_cases/all_cases.h | 31 ++++---- all_cases/short_code.cc | 160 ++++++++++++++++++++-------------------- 3 files changed, 95 insertions(+), 241 deletions(-) diff --git a/all_cases/all_cases.cc b/all_cases/all_cases.cc index e9f80f8..e69de29 100644 --- a/all_cases/all_cases.cc +++ b/all_cases/all_cases.cc @@ -1,145 +0,0 @@ -#include -#include "all_cases.h" - -//inline uint32_t binary_count(uint32_t bin) { // get number of non-zero bits -// bin -= (bin >> 1) & 0x55555555; -// bin = (bin & 0x33333333) + ((bin >> 2) & 0x33333333); -// bin = ((bin >> 4) + bin) & 0x0F0F0F0F; -//// return (bin * 0x01010101) >> 24; // AMD CPU -// bin += bin >> 8; -// bin += bin >> 16; -// return bin & 0b111111; -//} - -//uint32_t AllCases::binary_reverse(uint32_t bin) { // reverse binary every 2-bits -// bin = ((bin << 16) & 0xFFFF0000) | ((bin >> 16) & 0x0000FFFF); -// bin = ((bin << 8) & 0xFF00FF00) | ((bin >> 8) & 0x00FF00FF); -// bin = ((bin << 4) & 0xF0F0F0F0) | ((bin >> 4) & 0x0F0F0F0F); -// return ((bin << 2) & 0xCCCCCCCC) | ((bin >> 2) & 0x33333333); -//} - -//bool AllCases::check_case(uint32_t head, uint32_t range) { // check whether the case is valid -// uint32_t mask = 0b110011 << head; // fill 2x2 block -// for (int addr = 0; range; range >>= 2) { // traverse every 2-bits -// while (mask >> addr & 0b1) { -// ++addr; // search next not filled block -// } -// switch (range & 0b11) { -// case 0b00: // space block -// case 0b11: // 1x1 block -// if (addr > 19) { // invalid address -// return false; -// } -// mask |= 0b1 << addr; // fill 1x1 block -// break; -// case 0b10: // 2x1 block -// if (addr > 15 || mask >> (addr + 4) & 0b1) { // invalid address -// return false; -// } -// mask |= 0b10001 << addr; // fill 2x1 block -// break; -// case 0b01: // 1x2 block -// if (addr > 18 || (addr & 0b11) == 0b11 || mask >> (addr + 1) & 0b1) { // invalid address -// return false; -// } -// mask |= 0b11 << addr; // fill 1x2 block -// break; -// } -// } -// return true; // valid case -//} - -//void AllCases::generate_ranges(int n1, int n2, int n3, int n4) { // build target ranges -// int len, limit; -// constexpr uint32_t M_01 = 0b01 << 30; -// constexpr uint32_t M_10 = 0b10 << 30; -// constexpr uint32_t M_11 = 0b11 << 30; -// std::vector cache_1, cache_2; -// -// len = n1 + n2; -// limit = 0b1 << len; -// for (uint32_t bin = 0; bin < limit; ++bin) { -// if (binary_count(bin) != n2) { // skip binary without `n2` non-zero bits -// continue; -// } -// uint32_t range = 0; -// for (int i = 0; i < len; ++i) { // generate range base on binary value -// range >>= 2; -// if ((bin >> i) & 0b1) { // non-zero bit -// range |= M_01; // 01000... -// } -// } -// cache_1.emplace_back(range); // insert into first layer -// } -// -// len += n3; -// limit <<= n3; -// for (uint32_t bin = 0; bin < limit; ++bin) { -// if (binary_count(bin) != n3) { // skip binary without `n3` non-zero bits -// continue; -// } -// for (uint32_t base : cache_1) { // traverse first layer -// uint32_t range = 0; -// for (int i = 0; i < len; ++i) { // generate range base on binary value -// if ((bin >> i) & 0b1) { // non-zero bit -// (range >>= 2) |= M_10; // 10000... -// continue; -// } -// (range >>= 2) |= base & M_11; -// base <<= 2; -// } -// cache_2.emplace_back(range); // insert into second layer -// } -// } -// -// len += n4; -// limit <<= n4; -// for (uint32_t bin = 0; bin < limit; ++bin) { -// if (binary_count(bin) != n4) { // skip binary without `n4` non-zero bits -// continue; -// } -// for (uint32_t base : cache_2) { // traverse second layer -// uint32_t range = 0; -// for (int i = 0; i < len; ++i) { // generate range base on binary value -// if ((bin >> i) & 0b1) { // non-zero bit -// (range >>= 2) |= M_11; // 11000... -// continue; -// } -// (range >>= 2) |= base & M_11; -// base <<= 2; -// } -// basic_ranges.emplace_back(range); // insert into release ranges -// } -// } -//} - -//void AllCases::load_basic_ranges() { // load basic ranges -// for (int n = 0; n <= 7; ++n) { // number of 1x2 and 2x1 block -> 0 ~ 7 -// for (int n_2x1 = 0; n_2x1 <= n; ++n_2x1) { // number of 2x1 block -> 0 ~ n -// for (int n_1x1 = 0; n_1x1 <= (14 - n * 2); ++n_1x1) { // number of 1x1 block -> 0 ~ (14 - 2n) -// int n_1x2 = n - n_2x1; -// int n_space = 16 - n * 2 - n_1x1; -// /// 0x0 -> 00 | 1x2 -> 01 | 2x1 -> 10 | 1x1 -> 11 -// generate_ranges(n_space, n_1x2, n_2x1, n_1x1); // build target ranges -// } -// } -// } -// std::sort(basic_ranges.begin(), basic_ranges.end()); // sort basic ranges -// for (uint32_t &range : basic_ranges) { -// range = binary_reverse(range); // range reverse -// } -//} - -//void AllCases::find_all_cases() { // find all valid cases -// for (uint32_t head = 0; head < 16; ++head) { // address for 2x2 block -// if ((head & 0b11) == 0b11) { -// continue; -// } -// all_cases[head].clear(); -// for (uint32_t range : basic_ranges) { // combine 2x2 address and range -// if (check_case(head, range)) { -// all_cases[head].emplace_back(binary_reverse(range)); // found valid case -// } -// } -// } -//} diff --git a/all_cases/all_cases.h b/all_cases/all_cases.h index 2988610..41f8cca 100644 --- a/all_cases/all_cases.h +++ b/all_cases/all_cases.h @@ -3,20 +3,19 @@ #include #include -class AllCases { -public: - AllCases() { - load_basic_ranges(); - } - void find_all_cases(); - std::vector all_cases[16]; - std::vector basic_ranges; - - static uint32_t binary_reverse(uint32_t bin); - static bool check_case(uint32_t head, uint32_t range); - -private: - void load_basic_ranges(); - void generate_ranges(int n1, int n2, int n3, int n4); +//class AllCases { +//public: +// AllCases() { +// load_basic_ranges(); +// } +// void find_all_cases(); +// std::vector all_cases[16]; +// std::vector basic_ranges; +// +// static uint32_t binary_reverse(uint32_t bin); // static bool check_case(uint32_t head, uint32_t range); -}; +// +//private: +// void load_basic_ranges(); +// void generate_ranges(int n1, int n2, int n3, int n4); +//}; diff --git a/all_cases/short_code.cc b/all_cases/short_code.cc index 9a2a304..777b4ff 100644 --- a/all_cases/short_code.cc +++ b/all_cases/short_code.cc @@ -3,7 +3,7 @@ #include #include "all_cases.h" #include "short_code.h" -#include "short_code_mark.h" +//#include "short_code_mark.h" // TODO: try to remove: `0` `O` `I` `l` @@ -49,85 +49,85 @@ uint32_t code_from_string(const std::string &short_code) { return result; } -uint64_t unzip_short_code(uint32_t short_code) { - - auto a = AllCases(); // load basic ranges - - std::cout << "short code: " << short_code << std::endl; - - uint32_t head = 0; - for (; head < 16; ++head) { - if (short_code < ALL_CASES_INDEX[head]) { - break; - } - short_code -= ALL_CASES_INDEX[head]; - } - - std::cout << "head: " << head << std::endl; - std::cout << "short code: " << short_code << std::endl; - - uint32_t prefix = 0; - for (; prefix < 256; ++prefix) { - if (short_code < RANGE_PREFIX_INDEX[head][prefix]) { - break; - } - short_code -= RANGE_PREFIX_INDEX[head][prefix]; - } - - std::cout << "prefix: " << prefix << std::endl; - std::cout << "short code: " << short_code << std::endl; - - uint32_t range; - for (int i = 0; i < BASIC_RANGES_INDEX[prefix]; ++i) { - range = a.basic_ranges[i + BASIC_RANGES_OFFSET[prefix]]; - if (AllCases::check_case(head, range)) { - if (short_code == 0) { - break; - } - --short_code; - } - } - return (uint64_t)head << 32 | AllCases::binary_reverse(range); -} - -uint32_t zip_short_code(uint64_t code) { - auto a = AllCases(); // load basic ranges - - uint32_t head = code >> 32; - uint32_t head_offset = ALL_CASES_OFFSET[head]; - - std::cout << "head: " << head << std::endl; - std::cout << "head offset: " << head_offset << std::endl; - - uint32_t prefix = (code >> 24) & 0xFF; - uint32_t prefix_offset = RANGE_PREFIX_OFFSET[head][prefix]; - - std::cout << "prefix: " << prefix << std::endl; - std::cout << "prefix offset: " << prefix_offset << std::endl; - - uint32_t basic_index = BASIC_RANGES_INDEX[prefix]; - uint32_t basic_offset = BASIC_RANGES_OFFSET[prefix]; - - std::cout << "basic index: " << basic_index << std::endl; - std::cout << "basic offset: " << basic_offset << std::endl; - - auto target_range = AllCases::binary_reverse((uint32_t)code); - printf("target range -> %08X\n", target_range); - - uint32_t sub_offset = 0; - for (int i = 0; i < basic_index; ++i) { - uint32_t range = a.basic_ranges[i + basic_offset]; - if (range == target_range) { - break; - } - if (AllCases::check_case(head, range)) { - ++sub_offset; - } - } - std::cout << "sub offset: " << sub_offset << std::endl; +//uint64_t unzip_short_code(uint32_t short_code) { +// +// auto a = AllCases(); // load basic ranges +// +// std::cout << "short code: " << short_code << std::endl; +// +// uint32_t head = 0; +// for (; head < 16; ++head) { +// if (short_code < ALL_CASES_INDEX[head]) { +// break; +// } +// short_code -= ALL_CASES_INDEX[head]; +// } +// +// std::cout << "head: " << head << std::endl; +// std::cout << "short code: " << short_code << std::endl; +// +// uint32_t prefix = 0; +// for (; prefix < 256; ++prefix) { +// if (short_code < RANGE_PREFIX_INDEX[head][prefix]) { +// break; +// } +// short_code -= RANGE_PREFIX_INDEX[head][prefix]; +// } +// +// std::cout << "prefix: " << prefix << std::endl; +// std::cout << "short code: " << short_code << std::endl; +// +// uint32_t range; +// for (int i = 0; i < BASIC_RANGES_INDEX[prefix]; ++i) { +// range = a.basic_ranges[i + BASIC_RANGES_OFFSET[prefix]]; +// if (AllCases::check_case(head, range)) { +// if (short_code == 0) { +// break; +// } +// --short_code; +// } +// } +// return (uint64_t)head << 32 | AllCases::binary_reverse(range); +//} - return head_offset + prefix_offset + sub_offset; -} +//uint32_t zip_short_code(uint64_t code) { +// auto a = AllCases(); // load basic ranges +// +// uint32_t head = code >> 32; +// uint32_t head_offset = ALL_CASES_OFFSET[head]; +// +// std::cout << "head: " << head << std::endl; +// std::cout << "head offset: " << head_offset << std::endl; +// +// uint32_t prefix = (code >> 24) & 0xFF; +// uint32_t prefix_offset = RANGE_PREFIX_OFFSET[head][prefix]; +// +// std::cout << "prefix: " << prefix << std::endl; +// std::cout << "prefix offset: " << prefix_offset << std::endl; +// +// uint32_t basic_index = BASIC_RANGES_INDEX[prefix]; +// uint32_t basic_offset = BASIC_RANGES_OFFSET[prefix]; +// +// std::cout << "basic index: " << basic_index << std::endl; +// std::cout << "basic offset: " << basic_offset << std::endl; +// +// auto target_range = AllCases::binary_reverse((uint32_t)code); +// printf("target range -> %08X\n", target_range); +// +// uint32_t sub_offset = 0; +// for (int i = 0; i < basic_index; ++i) { +// uint32_t range = a.basic_ranges[i + basic_offset]; +// if (range == target_range) { +// break; +// } +// if (AllCases::check_case(head, range)) { +// ++sub_offset; +// } +// } +// std::cout << "sub offset: " << sub_offset << std::endl; +// +// return head_offset + prefix_offset + sub_offset; +//} int main() { @@ -139,7 +139,7 @@ int main() { return 0; - auto a = AllCases(); +// auto a = AllCases(); // a.find_all_cases(); // std::vector all_cases;