Browse Source

update: Core and FastCal module

master
Dnomd343 2 years ago
parent
commit
46d1ec2a64
  1. 10
      src/core/core.cc
  2. 13
      src/core/core.h
  3. 35
      src/fast_cal/fast_cal.cc
  4. 1
      src/fast_cal/fast_cal.h

10
src/core/core.cc

@ -170,13 +170,9 @@ void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases
continue; // B_space or B_fill
}
if (cache_size != 1) { // found one or more next cases
// TODO: try to send multi-items data
// for (int i = 1; i < cache_size; ++i) {
// release(cache[i].code, cache[i].mask); // release next cases
// }
release(cache, cache_size);
for (int i = 1; i < cache_size; ++i) {
release(cache[i].code, cache[i].mask); // release next cases
}
cache_size = 1; // reset cache size
}
}

13
src/core/core.h

@ -11,7 +11,12 @@
class Core {
public:
typedef std::function<void(uint64_t, uint64_t)> release_t;
void next_step(uint64_t code, uint64_t mask);
explicit Core(release_t release_func) : release(std::move(release_func)) {}
private:
struct cache_t {
uint64_t code; // case raw code
uint64_t mask; // only 000 or 111
@ -19,14 +24,6 @@ public:
int addr; // (0 ~ 19) * 3
};
// typedef std::function<void(uint64_t, uint64_t)> release_t;
typedef std::function<void(cache_t*, int)> release_t;
void next_step(uint64_t code, uint64_t mask);
explicit Core(release_t release_func) : release(std::move(release_func)) {}
private:
int cache_size = 1;
cache_t cache[16] = {0};
release_t release; // release code and mask

35
src/fast_cal/fast_cal.cc

@ -8,12 +8,11 @@
void FastCal::fast_cal(uint64_t code) {
std::cout << RawCode(code).dump_case() << std::endl;
// std::cout << RawCode(code).dump_case() << std::endl;
auto core = Core(
[this](auto &&p1, auto &&p2) {
// add_new_case(std::forward<decltype(p1)>(p1), std::forward<decltype(p2)>(p2));
add_new_case_demo(std::forward<decltype(p1)>(p1), std::forward<decltype(p2)>(p2));
[this](auto &&code, auto &&mask) { // lambda as function pointer
add_new_case(std::forward<decltype(code)>(code), std::forward<decltype(mask)>(mask));
}
);
@ -29,10 +28,10 @@ void FastCal::fast_cal(uint64_t code) {
while (!cache.empty()) {
// break check point
/// break check point
if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) {
std::cout << "Resolved" << std::endl;
// std::cout << RawCode(cache.front()->code).dump_case() << std::endl;
break;
}
@ -67,27 +66,3 @@ void FastCal::add_new_case(uint64_t code, uint64_t mask) {
cache.emplace(&cases[code]);
}
void FastCal::add_new_case_demo(Core::cache_t *cache_dat, int cache_size) {
for (int i = 1; i < cache_size; ++i) {
uint64_t code = cache_dat[i].code;
uint64_t mask = cache_dat[i].mask;
auto exist_case = cases.find(code);
if (exist_case != cases.end()) {
exist_case->second.mask |= mask;
continue;
}
cases[code] = fast_cal_t {
.code = code,
.mask = mask,
.last = cache.front(),
};
cache.emplace(&cases[code]);
}
}

1
src/fast_cal/fast_cal.h

@ -18,6 +18,5 @@ public:
void fast_cal(uint64_t code);
void add_new_case(uint64_t code, uint64_t mask);
void add_new_case_demo(Core::cache_t *cache_dat, int cache_size);
};

Loading…
Cancel
Save