|
@ -2,22 +2,8 @@ |
|
|
#include "short_code.h" |
|
|
#include "short_code.h" |
|
|
#include "short_code_mark.h" |
|
|
#include "short_code_mark.h" |
|
|
|
|
|
|
|
|
void ShortCode::build_base_ranges() { |
|
|
ShortCode::ShortCode(ShortCode::Mode mode) { // class initialize
|
|
|
auto all = AllCases(AllCases::InitType::WITH_BASIC_RANGES); |
|
|
speed_up(mode); |
|
|
basic_ranges = *all.get_basic_ranges(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ShortCode::build_mappings() { // build fast search mapping
|
|
|
|
|
|
auto all = AllCases(AllCases::InitType::WITH_ALL_CASES); |
|
|
|
|
|
for (int head = 0; head < 16; ++head) { |
|
|
|
|
|
uint64_t prefix = (uint64_t)head << 32; |
|
|
|
|
|
for (const auto &range : (*all.get_all_cases())[head]) { |
|
|
|
|
|
all_cases_list.emplace_back(prefix | range); // short_code => common_code
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for (int n = 0; n < all_cases_list.size(); ++n) { |
|
|
|
|
|
all_cases_dict[all_cases_list[n]] = n; // common_code => short_code
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
void ShortCode::speed_up(enum Mode mode) { // speed up handle short code
|
|
|
void ShortCode::speed_up(enum Mode mode) { // speed up handle short code
|
|
@ -35,6 +21,24 @@ void ShortCode::speed_up(enum Mode mode) { // speed up handle short code |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ShortCode::build_base_ranges() { // build basic ranges
|
|
|
|
|
|
auto all = AllCases(AllCases::Build::BASIC_RANGES); |
|
|
|
|
|
basic_ranges = *all.get_basic_ranges(); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void ShortCode::build_mappings() { // build fast search mappings
|
|
|
|
|
|
auto all = AllCases(AllCases::Build::ALL_CASES); |
|
|
|
|
|
for (int head = 0; head < 16; ++head) { |
|
|
|
|
|
uint64_t prefix = (uint64_t)head << 32; |
|
|
|
|
|
for (const auto &range : (*all.get_all_cases())[head]) { |
|
|
|
|
|
all_cases_list.emplace_back(prefix | range); // short_code => common_code
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
for (int n = 0; n < all_cases_list.size(); ++n) { |
|
|
|
|
|
all_cases_dict[all_cases_list[n]] = n; // common_code => short_code
|
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
uint64_t ShortCode::fast_decode(uint32_t short_code) { // short_code -> common_code
|
|
|
uint64_t ShortCode::fast_decode(uint32_t short_code) { // short_code -> common_code
|
|
|
// TODO: ensure input short_code < SHORT_CODE_LIMIT
|
|
|
// TODO: ensure input short_code < SHORT_CODE_LIMIT
|
|
|
return all_cases_list[short_code]; |
|
|
return all_cases_list[short_code]; |
|
@ -44,7 +48,3 @@ uint32_t ShortCode::fast_encode(uint64_t common_code) { // common_code -> short_ |
|
|
// TODO: ensure input common_code valid
|
|
|
// TODO: ensure input common_code valid
|
|
|
return all_cases_dict[common_code]; |
|
|
return all_cases_dict[common_code]; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ShortCode::ShortCode(ShortCode::Mode mode) { |
|
|
|
|
|
speed_up(mode); |
|
|
|
|
|
} |
|
|
|
|
|