aboutsummaryrefslogtreecommitdiff
path: root/cpp
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-05-25 12:11:34 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-05-25 12:11:34 +0200
commit238702e7dd860af59d22f33cbfe163f28c3beb4e (patch)
tree577adc495c4e5284f357e44e2877e8c848d79a24 /cpp
parente1690a427040f710de5643643d7c6226c1b2364f (diff)
downloadnissy-core-238702e7dd860af59d22f33cbfe163f28c3beb4e.tar.gz
nissy-core-238702e7dd860af59d22f33cbfe163f28c3beb4e.zip
Cleanup
Diffstat (limited to 'cpp')
-rw-r--r--cpp/examples/solve_h48h3k2.cpp5
-rw-r--r--cpp/nissy.cpp23
-rw-r--r--cpp/nissy.h3
3 files changed, 12 insertions, 19 deletions
diff --git a/cpp/examples/solve_h48h3k2.cpp b/cpp/examples/solve_h48h3k2.cpp
index f0d6f2f..2a226ba 100644
--- a/cpp/examples/solve_h48h3k2.cpp
+++ b/cpp/examples/solve_h48h3k2.cpp
@@ -80,10 +80,9 @@ int main() {
80 if (solve_result.solutions.size() == 0) { 80 if (solve_result.solutions.size() == 0) {
81 std::cout << "No solution found!" << std::endl; 81 std::cout << "No solution found!" << std::endl;
82 } else { 82 } else {
83 auto& sol = solve_result.solutions[0]; 83 auto len = nissy::count_moves(solve_result.solutions).value;
84 auto len = nissy::count_moves(sol).value;
85 std::cout << "Solution (" << len << " moves): " 84 std::cout << "Solution (" << len << " moves): "
86 << sol << std::endl; 85 << solve_result.solutions << std::endl;
87 } 86 }
88 87
89 return 0; 88 return 0;
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 }
diff --git a/cpp/nissy.h b/cpp/nissy.h
index 884043d..817307c 100644
--- a/cpp/nissy.h
+++ b/cpp/nissy.h
@@ -79,8 +79,7 @@ namespace nissy {
79 public: 79 public:
80 struct solve_result { 80 struct solve_result {
81 error err; 81 error err;
82 std::vector<std::string> solutions; 82 std::string solutions;
83 std::array<long long, 10> stats;
84 }; 83 };
85 84
86 const std::string name; 85 const std::string name;

Generated with cgit - Back to sebastiano.tronto.net