diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-25 12:11:34 +0200 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2025-05-25 12:11:34 +0200 |
| commit | 238702e7dd860af59d22f33cbfe163f28c3beb4e (patch) | |
| tree | 577adc495c4e5284f357e44e2877e8c848d79a24 /cpp/nissy.cpp | |
| parent | e1690a427040f710de5643643d7c6226c1b2364f (diff) | |
| download | nissy-core-238702e7dd860af59d22f33cbfe163f28c3beb4e.tar.gz nissy-core-238702e7dd860af59d22f33cbfe163f28c3beb4e.zip | |
Cleanup
Diffstat (limited to '')
| -rw-r--r-- | cpp/nissy.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp index ed0dc0f..36fb5f2 100644 --- a/cpp/nissy.cpp +++ b/cpp/nissy.cpp | |||
| @@ -56,6 +56,7 @@ namespace nissy { | |||
| 56 | namespace size { | 56 | namespace size { |
| 57 | constexpr size_t CUBE = 24; | 57 | constexpr size_t CUBE = 24; |
| 58 | constexpr size_t TRANSFORMATION = 12; | 58 | constexpr size_t TRANSFORMATION = 12; |
| 59 | constexpr size_t SOLVE_STATS = 10; | ||
| 59 | constexpr size_t DATAID = 255; | 60 | constexpr size_t DATAID = 255; |
| 60 | } | 61 | } |
| 61 | 62 | ||
| @@ -163,34 +164,28 @@ namespace nissy { | |||
| 163 | unsigned threads, int (*poll_status)(void *), | 164 | unsigned threads, int (*poll_status)(void *), |
| 164 | void *poll_status_data) const | 165 | void *poll_status_data) const |
| 165 | { | 166 | { |
| 167 | long long stats[size::SOLVE_STATS]; | ||
| 166 | solver::solve_result result; | 168 | solver::solve_result result; |
| 167 | 169 | ||
| 168 | if (maxsols == 0) { | 170 | if (maxsols == 0) { |
| 169 | result.solutions = {}; | 171 | result.solutions = ""; |
| 170 | result.err = error::OK; | 172 | result.err = error::OK; |
| 171 | return result; | 173 | return result; |
| 172 | } | 174 | } |
| 173 | 175 | ||
| 174 | const size_t len = 3 * (maxmoves+1) * maxsols; | 176 | const size_t len = 3 * (maxmoves+1) * maxsols; |
| 175 | std::vector<char> csols(len); | 177 | result.solutions.resize(len); |
| 176 | 178 | ||
| 177 | auto err = nissy_solve(cube.to_string().c_str(), | 179 | auto err = nissy_solve(cube.to_string().c_str(), |
| 178 | name.c_str(), niss.value, minmoves, maxmoves, maxsols, | 180 | name.c_str(), niss.value, minmoves, maxmoves, maxsols, |
| 179 | optimal, threads, data.size(), | 181 | optimal, threads, data.size(), |
| 180 | reinterpret_cast<const unsigned char *>(data.data()), len, | 182 | reinterpret_cast<const unsigned char *>(data.data()), len, |
| 181 | csols.data(), result.stats.data(), poll_status, | 183 | result.solutions.data(), stats, |
| 182 | poll_status_data); | 184 | poll_status, poll_status_data); |
| 183 | result.err = error{err}; | ||
| 184 | 185 | ||
| 185 | if (err < 0) | 186 | int size = result.solutions.find_first_of('\0') + 1; |
| 186 | return result; | 187 | result.solutions.resize(size); |
| 187 | 188 | result.err = error{err}; | |
| 188 | std::string_view strsols(csols.data()); | ||
| 189 | for (auto r : strsols | std::views::split('\n')) | ||
| 190 | if (r.begin() != r.end() || | ||
| 191 | r.begin() == strsols.begin()) | ||
| 192 | result.solutions.push_back( | ||
| 193 | std::string{r.begin(), r.end()}); | ||
| 194 | 189 | ||
| 195 | return result; | 190 | return result; |
| 196 | } | 191 | } |
