Browse Source

perf: nearly complete Core module

master
Dnomd343 2 years ago
parent
commit
e283dd436f
  1. 36
      src/core/core.cc
  2. 16
      src/core/core.h
  3. 10
      src/fast_cal/fast_cal.cc

36
src/core/core.cc

@ -60,22 +60,18 @@ cache_insert(next_case);
//////////////////////////////////////// ////////////////////////////////////////
//inline void Core::cache_insert(Core::cache_t &next_case) { // try to insert into cache inline void Core::cache_insert(Core::cache_t &next_case) { // try to insert into cache
template<typename T> auto *cache_ptr = cache;
inline void Core<T>::cache_insert(Core::cache_t &next_case) { // try to insert into cache for (; cache_ptr < cache + cache_size; ++cache_ptr) {
auto *p = cache; if (cache_ptr->code == next_case.code) {
for (; p < cache + cache_size; ++p) {
if (p->code == next_case.code) {
return; // already exist -> insert failed return; // already exist -> insert failed
} }
} }
*p = next_case; *cache_ptr = next_case; // cache push back
++cache_size; ++cache_size;
} }
//void Core::move_1x1(uint64_t code, int addr) { // try to move target 1x1 block void Core::move_1x1(uint64_t code, int addr) { // try to move target 1x1 block
template<typename T>
void Core<T>::move_1x1(uint64_t code, int addr) { // try to move target 1x1 block
BFS_INIT BFS_INIT
while (!BFS_STOP) { // bfs search process while (!BFS_STOP) { // bfs search process
BFS_LOAD BFS_LOAD
@ -94,9 +90,7 @@ void Core<T>::move_1x1(uint64_t code, int addr) { // try to move target 1x1 bloc
} }
} }
//void Core::move_1x2(uint64_t code, int addr) { // try to move target 1x2 block void Core::move_1x2(uint64_t code, int addr) { // try to move target 1x2 block
template<typename T>
void Core<T>::move_1x2(uint64_t code, int addr) { // try to move target 1x2 block
BFS_INIT BFS_INIT
while (!BFS_STOP) { // bfs search process while (!BFS_STOP) { // bfs search process
BFS_LOAD BFS_LOAD
@ -115,9 +109,7 @@ void Core<T>::move_1x2(uint64_t code, int addr) { // try to move target 1x2 bloc
} }
} }
//void Core::move_2x1(uint64_t code, int addr) { // try to move target 2x1 block void Core::move_2x1(uint64_t code, int addr) { // try to move target 2x1 block
template<typename T>
void Core<T>::move_2x1(uint64_t code, int addr) { // try to move target 2x1 block
BFS_INIT BFS_INIT
while (!BFS_STOP) { // bfs search process while (!BFS_STOP) { // bfs search process
BFS_LOAD BFS_LOAD
@ -136,9 +128,7 @@ void Core<T>::move_2x1(uint64_t code, int addr) { // try to move target 2x1 bloc
} }
} }
//void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block void Core::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block
template<typename T>
void Core<T>::move_2x2(uint64_t code, int addr) { // try to move target 2x2 block
BFS_INIT BFS_INIT
while (!BFS_STOP) { // bfs search process while (!BFS_STOP) { // bfs search process
BFS_LOAD BFS_LOAD
@ -157,9 +147,7 @@ void Core<T>::move_2x2(uint64_t code, int addr) { // try to move target 2x2 bloc
} }
} }
//void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases void Core::next_step(uint64_t code, uint64_t mask) { // search next step cases
template<typename T>
void Core<T>::next_step(uint64_t code, uint64_t mask) { // search next step cases
cache[0].filter = 0; // without filter cache[0].filter = 0; // without filter
cache[0].code = code; // bfs root code cache[0].code = code; // bfs root code
auto range = code | mask; auto range = code | mask;
@ -185,9 +173,7 @@ void Core<T>::next_step(uint64_t code, uint64_t mask) { // search next step case
// TODO: try to send multi-items data // TODO: try to send multi-items data
for (int i = 1; i < cache_size; ++i) { for (int i = 1; i < cache_size; ++i) {
(src_class->*release)(cache[i].code, cache[i].mask); release(cache[i].code, cache[i].mask); // release next cases
// release(cache[i].code, cache[i].mask); // release next cases
// release_next(cache[i].code, cache[i].mask); // release next cases
} }
cache_size = 1; // reset cache size cache_size = 1; // reset cache size

16
src/core/core.h

@ -8,21 +8,12 @@
#define DOWN (+4 * 3) #define DOWN (+4 * 3)
#define RIGHT (+1 * 3) #define RIGHT (+1 * 3)
class FastCal;
template<typename T>
class Core { class Core {
public: public:
typedef std::function<void(uint64_t, uint64_t)> release_t;
typedef void (T::*release_t)(uint64_t, uint64_t);
T *src_class;
release_t release;
std::function<void(uint64_t, uint64_t)> release_next;
void next_step(uint64_t code, uint64_t mask); void next_step(uint64_t code, uint64_t mask);
// explicit Core(release_t release_func) : release(release_func) {} explicit Core(release_t release_func) : release(release_func) {}
private: private:
struct cache_t { struct cache_t {
@ -34,11 +25,12 @@ 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
void move_1x1(uint64_t code, int addr); void move_1x1(uint64_t code, int addr);
void move_1x2(uint64_t code, int addr); void move_1x2(uint64_t code, int addr);
void move_2x1(uint64_t code, int addr); void move_2x1(uint64_t code, int addr);
void move_2x2(uint64_t code, int addr); void move_2x2(uint64_t code, int addr);
inline void cache_insert(Core::cache_t &next_case); inline void cache_insert(Core::cache_t &next_case);
}; };

10
src/fast_cal/fast_cal.cc

@ -10,13 +10,9 @@ 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(
// core.release_next = std::bind(&FastCal::add_new_case, this, std::placeholders::_1, std::placeholders::_2); std::bind(&FastCal::add_new_case, this, std::placeholders::_1, std::placeholders::_2)
);
auto core = Core<FastCal>();
core.src_class = this;
core.release = &FastCal::add_new_case;
cases.empty(); cases.empty();
cache.empty(); cache.empty();

Loading…
Cancel
Save