Browse Source

update: Core and FastCal module

legacy
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 continue; // B_space or B_fill
} }
if (cache_size != 1) { // found one or more next cases if (cache_size != 1) { // found one or more next cases
for (int i = 1; i < cache_size; ++i) {
// TODO: try to send multi-items data release(cache[i].code, cache[i].mask); // release next cases
// for (int i = 1; i < cache_size; ++i) { }
// release(cache[i].code, cache[i].mask); // release next cases
// }
release(cache, cache_size);
cache_size = 1; // reset cache size cache_size = 1; // reset cache size
} }
} }

13
src/core/core.h

@ -11,7 +11,12 @@
class Core { class Core {
public: 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 { struct cache_t {
uint64_t code; // case raw code uint64_t code; // case raw code
uint64_t mask; // only 000 or 111 uint64_t mask; // only 000 or 111
@ -19,14 +24,6 @@ public:
int addr; // (0 ~ 19) * 3 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; int cache_size = 1;
cache_t cache[16] = {0}; cache_t cache[16] = {0};
release_t release; // release code and mask 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) { 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( auto core = Core(
[this](auto &&p1, auto &&p2) { [this](auto &&code, auto &&mask) { // lambda as function pointer
// add_new_case(std::forward<decltype(p1)>(p1), std::forward<decltype(p2)>(p2)); add_new_case(std::forward<decltype(code)>(code), std::forward<decltype(mask)>(mask));
add_new_case_demo(std::forward<decltype(p1)>(p1), std::forward<decltype(p2)>(p2));
} }
); );
@ -29,10 +28,10 @@ void FastCal::fast_cal(uint64_t code) {
while (!cache.empty()) { while (!cache.empty()) {
// break check point /// break check point
if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) { if (((cache.front()->code >> (3 * 0xD)) & 0b111) == B_2x2) {
std::cout << "Resolved" << std::endl; std::cout << "Resolved" << std::endl;
// std::cout << RawCode(cache.front()->code).dump_case() << std::endl;
break; break;
} }
@ -67,27 +66,3 @@ void FastCal::add_new_case(uint64_t code, uint64_t mask) {
cache.emplace(&cases[code]); 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 fast_cal(uint64_t code);
void add_new_case(uint64_t code, uint64_t mask); 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