|
|
@ -34,11 +34,16 @@ struct data_t { |
|
|
|
template <typename T> |
|
|
|
class MyQueue { |
|
|
|
public: |
|
|
|
// MyQueue() = default;
|
|
|
|
|
|
|
|
explicit MyQueue(size_t reserve) { |
|
|
|
// vec_.reserve(reserve);
|
|
|
|
vec_.resize(reserve); |
|
|
|
} |
|
|
|
|
|
|
|
// void reserve(size_t size) {
|
|
|
|
// vec_.resize(size);
|
|
|
|
// }
|
|
|
|
|
|
|
|
void emplace_back(T item) { |
|
|
|
// vec_.emplace_back(item);
|
|
|
|
vec_[iter_] = item; |
|
|
@ -57,7 +62,7 @@ public: |
|
|
|
return offset_ == iter_; |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
//private:
|
|
|
|
size_t iter_ {0}; |
|
|
|
size_t offset_ {0}; |
|
|
|
std::vector<T> vec_ {}; |
|
|
@ -66,9 +71,11 @@ private: |
|
|
|
class FCDemo { |
|
|
|
public: |
|
|
|
explicit FCDemo(RawCode raw_code) : codes_(GroupUnion::from_raw_code(raw_code).max_group_size()) { |
|
|
|
// TODO: build codes_ with reserve size
|
|
|
|
auto reserve = GroupUnion::from_raw_code(raw_code).max_group_size(); |
|
|
|
// codes_.reserve(reserve);
|
|
|
|
cases_.reserve(286730); |
|
|
|
// cases_.reserve(static_cast<size_t>(reserve * 1.56));
|
|
|
|
cases_.reserve(static_cast<size_t>(25955 * 1.56)); |
|
|
|
codes_.emplace_back(raw_code.unwrap()); |
|
|
|
cases_.emplace(raw_code, data_t {0, 0}); // without mask
|
|
|
|
} |
|
|
@ -78,13 +85,11 @@ public: |
|
|
|
auto core = MaskMover([this, &result](uint64_t code, uint64_t mask) { |
|
|
|
if (const auto match = cases_.find(code); match != cases_.end()) { |
|
|
|
match->second.mask |= mask; // update mask
|
|
|
|
// match.value().mask |= mask; // update mask
|
|
|
|
return; |
|
|
|
} |
|
|
|
cases_.emplace(code, data_t { |
|
|
|
.mask = mask, |
|
|
|
.back = codes_.front(), |
|
|
|
// .back = codes_[offset_].unwrap(),
|
|
|
|
}); |
|
|
|
codes_.emplace_back(code); |
|
|
|
|
|
|
@ -99,56 +104,68 @@ public: |
|
|
|
codes_.pop(); |
|
|
|
|
|
|
|
if (result != 0) { |
|
|
|
// std::cout << cases_.size() << std::endl;
|
|
|
|
// std::cout << cases_.load_factor() << std::endl;
|
|
|
|
return RawCode::unsafe_create(result); |
|
|
|
} |
|
|
|
} |
|
|
|
return RawCode::unsafe_create(0); |
|
|
|
} |
|
|
|
|
|
|
|
std::vector<RawCode> DoCalMulti() { |
|
|
|
// uint64_t result = 0;
|
|
|
|
bool stop_flag = false; |
|
|
|
std::vector<RawCode> results {}; |
|
|
|
|
|
|
|
auto core = MaskMover([this, &stop_flag, &results](uint64_t code, uint64_t mask) { |
|
|
|
if (const auto match = cases_.find(code); match != cases_.end()) { |
|
|
|
match->second.mask |= mask; // update mask
|
|
|
|
return; |
|
|
|
} |
|
|
|
cases_.emplace(code, data_t { |
|
|
|
.mask = mask, |
|
|
|
.back = codes_.front(), |
|
|
|
}); |
|
|
|
codes_.emplace_back(code); |
|
|
|
|
|
|
|
if (((code >> 39) & 0b111) == 0b100) { |
|
|
|
stop_flag = true; |
|
|
|
// result = code;
|
|
|
|
results.emplace_back(RawCode::unsafe_create(code)); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
std::cout << cases_.load_factor() << std::endl; |
|
|
|
size_t layer_end = 1; |
|
|
|
|
|
|
|
return RawCode::unsafe_create(0); |
|
|
|
while (!codes_.empty()) { |
|
|
|
auto curr = codes_.front(); |
|
|
|
core.next_cases(curr, cases_.find(curr)->second.mask); |
|
|
|
codes_.pop(); |
|
|
|
|
|
|
|
// while (offset_ != codes_.size()) {
|
|
|
|
// auto curr = codes_[offset_].unwrap();
|
|
|
|
// core.next_cases(curr, cases_.find(curr)->second.mask);
|
|
|
|
// ++offset_;
|
|
|
|
//
|
|
|
|
// if (result != 0) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
if (codes_.offset_ == layer_end) { |
|
|
|
// std::cout << "layer: " << codes_.offset_ << std::endl;
|
|
|
|
layer_end = codes_.iter_; |
|
|
|
if (stop_flag) { |
|
|
|
return results; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// std::vector<RawCode> path;
|
|
|
|
// auto code = result;
|
|
|
|
// while (true) {
|
|
|
|
// if (code == 0) {
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// path.emplace_back(RawCode::unsafe_create(code));
|
|
|
|
// code = cases_.find(code)->second.back;
|
|
|
|
// }
|
|
|
|
// std::reverse(path.begin(), path.end());
|
|
|
|
// for (auto step : path) {
|
|
|
|
// std::cout << step << std::endl;
|
|
|
|
// if (result != 0) {
|
|
|
|
// return RawCode::unsafe_create(result);
|
|
|
|
// }
|
|
|
|
// std::cout << path.size() << std::endl;
|
|
|
|
|
|
|
|
// return codes_[offset_];
|
|
|
|
} |
|
|
|
return {}; |
|
|
|
} |
|
|
|
|
|
|
|
private: |
|
|
|
// uint64_t offset_ {0};
|
|
|
|
MyQueue<uint64_t> codes_; |
|
|
|
// absl::flat_hash_map<uint64_t, data_t> cases_; // <code, mask>
|
|
|
|
// robin_hood::unordered_map<uint64_t, data_t> cases_;
|
|
|
|
// ankerl::unordered_dense::map<uint64_t, data_t> cases_;
|
|
|
|
// tsl::robin_map<uint64_t, data_t> cases_;
|
|
|
|
phmap::flat_hash_map<uint64_t, data_t> cases_; |
|
|
|
}; |
|
|
|
|
|
|
|
RawCode FastCal_demo(RawCode raw_code) { |
|
|
|
FCDemo fc {raw_code}; |
|
|
|
return fc.DoCal(); |
|
|
|
// return fc.DoCal();
|
|
|
|
auto tmp = fc.DoCalMulti(); |
|
|
|
// for (auto code : tmp) {
|
|
|
|
// std::cout << code << std::endl;
|
|
|
|
// }
|
|
|
|
return tmp[0]; |
|
|
|
} |
|
|
|