Browse Source

update: interface for get status

legacy
Dnomd343 2 years ago
parent
commit
66ed2bacfa
  1. 2
      src/CMakeLists.txt
  2. 2
      src/all_cases/all_cases.cc
  3. 2
      src/all_cases/all_cases.h
  4. 2
      src/all_cases/basic_ranges.cc
  5. 2
      src/all_cases/basic_ranges.h
  6. 105
      src/main.cc

2
src/CMakeLists.txt

@ -14,3 +14,5 @@ add_executable(klotski main.cc)
target_link_libraries(klotski all_cases) target_link_libraries(klotski all_cases)
target_link_libraries(klotski short_code) target_link_libraries(klotski short_code)
target_link_libraries(klotski common_code) target_link_libraries(klotski common_code)
target_link_libraries(klotski pthread)

2
src/all_cases/all_cases.cc

@ -5,7 +5,7 @@ std::mutex AllCases::all_cases_building;
bool AllCases::all_cases_available = false; bool AllCases::all_cases_available = false;
std::vector<uint32_t> AllCases::all_cases[]; std::vector<uint32_t> AllCases::all_cases[];
AllCases::Status AllCases::all_cases_status() { // get all cases status AllCases::Status AllCases::get_status() { // get all cases status
if (all_cases_available) { if (all_cases_available) {
return AVAILABLE; // all cases already built return AVAILABLE; // all cases already built
} }

2
src/all_cases/all_cases.h

@ -8,7 +8,7 @@
class AllCases : public BasicRanges { class AllCases : public BasicRanges {
public: public:
static void build_all_cases(); static void build_all_cases();
static enum Status all_cases_status(); static enum Status get_status();
static const std::vector<uint32_t> (*get_all_cases())[16]; static const std::vector<uint32_t> (*get_all_cases())[16];
private: private:

2
src/all_cases/basic_ranges.cc

@ -15,7 +15,7 @@ inline uint32_t binary_count(uint32_t bin) { // get number of non-zero bits
return bin & 0b111111; return bin & 0b111111;
} }
BasicRanges::Status BasicRanges::basic_ranges_status() { // get basic ranges status BasicRanges::Status BasicRanges::get_status() { // get basic ranges status
if (basic_ranges_available) { if (basic_ranges_available) {
return AVAILABLE; // basic ranges already built return AVAILABLE; // basic ranges already built
} }

2
src/all_cases/basic_ranges.h

@ -11,8 +11,8 @@ public:
BUILDING, BUILDING,
AVAILABLE, AVAILABLE,
}; };
static enum Status get_status();
static void build_basic_ranges(); static void build_basic_ranges();
static enum Status basic_ranges_status(); // TODO: convert to get_status function
static const std::vector<uint32_t>* get_basic_ranges(); static const std::vector<uint32_t>* get_basic_ranges();
private: private:

105
src/main.cc

@ -4,46 +4,51 @@
#include "common_code.h" #include "common_code.h"
#include "short_code.h" #include "short_code.h"
//void get_status() { #include <thread>
// switch (BasicRanges::basic_ranges_status()) {
// case BasicRanges::NO_INIT: void get_status() {
// std::cout << "basic ranges no init" << std::endl; switch (BasicRanges::get_status()) {
// break; case BasicRanges::NO_INIT:
// case BasicRanges::BUILDING: std::cout << "basic ranges no init" << std::endl;
// std::cout << "basic ranges building" << std::endl; break;
// break; case BasicRanges::BUILDING:
// case BasicRanges::AVAILABLE: std::cout << "basic ranges building" << std::endl;
// std::cout << "basic ranges available" << std::endl; break;
// break; case BasicRanges::AVAILABLE:
// } std::cout << "basic ranges available" << std::endl;
// break;
// switch (AllCases::all_cases_status()) { }
// case AllCases::NO_INIT:
// std::cout << "all cases no init" << std::endl; switch (AllCases::get_status()) {
// break; case AllCases::NO_INIT:
// case AllCases::BUILDING: std::cout << "all cases no init" << std::endl;
// std::cout << "all cases building" << std::endl; break;
// break; case AllCases::BUILDING:
// case AllCases::AVAILABLE: std::cout << "all cases building" << std::endl;
// std::cout << "all cases available" << std::endl; break;
// break; case AllCases::AVAILABLE:
// } std::cout << "all cases available" << std::endl;
//} break;
}
}
int main() { int main() {
// get_status(); get_status();
// BasicRanges::build_basic_ranges(); BasicRanges::build_basic_ranges();
// get_status(); get_status();
// AllCases::build_all_cases(); AllCases::build_all_cases();
// get_status(); get_status();
//
// for (auto const &all_case : *AllCases::get_all_cases()) { for (auto const &all_case : *AllCases::get_all_cases()) {
// std::cout << " " << all_case.size() << std::endl; std::cout << " " << all_case.size() << std::endl;
// } }
//
// std::cout << BasicRanges::get_basic_ranges() << std::endl; std::cout << BasicRanges::get_basic_ranges() << std::endl;
// std::cout << AllCases::get_basic_ranges() << std::endl; std::cout << AllCases::get_basic_ranges() << std::endl;
printf("%p\n", BasicRanges::get_status);
printf("%p\n", AllCases::get_status);
// std::cout << CommonCode::check(0x123456789) << std::endl; // std::cout << CommonCode::check(0x123456789) << std::endl;
@ -62,15 +67,23 @@ int main() {
// std::cout << CommonCode(0x1A9BF0C00).to_string() << std::endl; // std::cout << CommonCode(0x1A9BF0C00).to_string() << std::endl;
std::cout << "start NORMAL speed up" << std::endl; // std::cout << "start NORMAL speed up" << std::endl;
ShortCode::speed_up(ShortCode::NORMAL); //// ShortCode::speed_up(ShortCode::NORMAL);
std::cout << "NORMAL speed up complete" << std::endl; // std::thread t1(ShortCode::speed_up, ShortCode::NORMAL);
// std::thread t2(ShortCode::speed_up, ShortCode::NORMAL);
std::cout << "start FAST speed up" << std::endl; // t1.join();
ShortCode::speed_up(ShortCode::FAST); // t2.join();
std::cout << "FAST speed up complete" << std::endl; // std::cout << "NORMAL speed up complete" << std::endl;
//
std::cout << ShortCode::all_cases_list.size() << std::endl; // std::cout << "start FAST speed up" << std::endl;
//// ShortCode::speed_up(ShortCode::FAST);
// std::thread t3(ShortCode::speed_up, ShortCode::FAST);
// std::thread t4(ShortCode::speed_up, ShortCode::FAST);
// t3.join();
// t4.join();
// std::cout << "FAST speed up complete" << std::endl;
//
// std::cout << ShortCode::all_cases_list.size() << std::endl;
return 0; return 0;
} }

Loading…
Cancel
Save