aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastiano Tronto <sebastiano@tronto.net>2025-04-22 14:47:25 +0200
committerSebastiano Tronto <sebastiano@tronto.net>2025-04-22 14:47:25 +0200
commit93522effba2f200257141189de5925a23fca93b8 (patch)
tree96d94b56017f1448832b5dc9e24bfcb31183f13c
parent1fb55fe25b3dd5ef61dbc38290fbba2e233dc6b6 (diff)
downloadnissy-core-93522effba2f200257141189de5925a23fca93b8.tar.gz
nissy-core-93522effba2f200257141189de5925a23fca93b8.zip
Remove compose from the public API
Diffstat (limited to '')
-rw-r--r--README.md4
-rw-r--r--cpp/nissy.cpp9
-rw-r--r--cpp/nissy.h1
-rw-r--r--python/nissy_module.c27
-rw-r--r--shell/shell.c34
-rwxr-xr-xshell/test.sh22
-rw-r--r--shell/testcases/000_frommoves.in1
-rw-r--r--shell/testcases/000_frommoves.out1
-rw-r--r--shell/testcases/001_compose.in1
-rw-r--r--shell/testcases/001_compose.out1
-rw-r--r--src/nissy.c41
-rw-r--r--src/nissy.h25
12 files changed, 2 insertions, 165 deletions
diff --git a/README.md b/README.md
index 44423a6..302928a 100644
--- a/README.md
+++ b/README.md
@@ -241,8 +241,8 @@ $ python # In the main folder
241From here you can call the library functions directly, for example: 241From here you can call the library functions directly, for example:
242 242
243``` 243```
244>>> nissy.compose('NEORSQLH=ZFCYUAGLHTKB=A', 'NEORSQLH=ZFCYUAGLHTKB=A') 244>>> nissy.applymoves('ABCDEFGH=ABCDEFGHIJKL=A', "R U R' U'")
245'ASTUGFBH=DACXEZGBLIKF=A' 245'WFCDERQH=AECDIFGHBJKL=A'
246``` 246```
247 247
248The `python/examples` folder contains some examples, that you 248The `python/examples` folder contains some examples, that you
diff --git a/cpp/nissy.cpp b/cpp/nissy.cpp
index 3535553..a077c50 100644
--- a/cpp/nissy.cpp
+++ b/cpp/nissy.cpp
@@ -9,7 +9,6 @@ TODO: add more documentation (here and in README.md)
9#include <fstream> 9#include <fstream>
10 10
11extern "C" { 11extern "C" {
12 long long nissy_compose(const char *, const char *, char *);
13 long long nissy_inverse(const char *, char *); 12 long long nissy_inverse(const char *, char *);
14 long long nissy_applymoves(const char *, const char *, char *); 13 long long nissy_applymoves(const char *, const char *, char *);
15 long long nissy_applytrans(const char *, const char *, char *); 14 long long nissy_applytrans(const char *, const char *, char *);
@@ -87,14 +86,6 @@ namespace nissy {
87 m_str = result; 86 m_str = result;
88 } 87 }
89 88
90 void cube::compose(const cube& other)
91 {
92 char result[size::CUBE];
93 nissy_compose(
94 m_str.c_str(), other.to_string().c_str(), result);
95 m_str = result;
96 }
97
98 std::string cube::to_string() const { return m_str; } 89 std::string cube::to_string() const { return m_str; }
99 90
100 std::variant<cube, error> 91 std::variant<cube, error>
diff --git a/cpp/nissy.h b/cpp/nissy.h
index 2eb0f42..8fd0aff 100644
--- a/cpp/nissy.h
+++ b/cpp/nissy.h
@@ -52,7 +52,6 @@ namespace nissy {
52 error move(const std::string&); 52 error move(const std::string&);
53 error transform(const std::string&); 53 error transform(const std::string&);
54 void invert(); 54 void invert();
55 void compose(const cube&);
56 std::string to_string() const; 55 std::string to_string() const;
57 56
58 static std::variant<cube, error> from_string( 57 static std::variant<cube, error> from_string(
diff --git a/python/nissy_module.c b/python/nissy_module.c
index 58a5b67..5378c72 100644
--- a/python/nissy_module.c
+++ b/python/nissy_module.c
@@ -61,32 +61,6 @@ long_result(long long result)
61 return PyLong_FromLong(result); 61 return PyLong_FromLong(result);
62} 62}
63 63
64
65PyDoc_STRVAR(compose_doc,
66"compose(cube, permutation)\n"
67"--\n\n"
68"Apply 'permutation' on 'cube'.\n"
69"\n"
70"Parameters:\n"
71" - cube: a cube\n"
72" - permutation: another cube\n"
73"\n"
74"Returns: the resulting cube string\n"
75);
76static PyObject *
77compose(PyObject *self, PyObject *args)
78{
79 long long err;
80 const char *cube, *permutation;
81 char result[NISSY_SIZE_CUBE];
82
83 if (!PyArg_ParseTuple(args, "ss", &cube, &permutation))
84 return NULL;
85
86 err = nissy_compose(cube, permutation, result);
87 return string_result(err, result);
88}
89
90PyDoc_STRVAR(inverse_doc, 64PyDoc_STRVAR(inverse_doc,
91"inverse(cube)\n" 65"inverse(cube)\n"
92"--\n\n" 66"--\n\n"
@@ -368,7 +342,6 @@ countmoves(PyObject *self, PyObject *args)
368} 342}
369 343
370static PyMethodDef nissy_methods[] = { 344static PyMethodDef nissy_methods[] = {
371 { "compose", compose, METH_VARARGS, compose_doc },
372 { "inverse", inverse, METH_VARARGS, inverse_doc }, 345 { "inverse", inverse, METH_VARARGS, inverse_doc },
373 { "applymoves", applymoves, METH_VARARGS, applymoves_doc }, 346 { "applymoves", applymoves, METH_VARARGS, applymoves_doc },
374 { "applytrans", applytrans, METH_VARARGS, applytrans_doc }, 347 { "applytrans", applytrans, METH_VARARGS, applytrans_doc },
diff --git a/shell/shell.c b/shell/shell.c
index ecd39f2..40a5748 100644
--- a/shell/shell.c
+++ b/shell/shell.c
@@ -15,7 +15,6 @@
15#define MAX_PATH_LENGTH UINT64_C(10000) 15#define MAX_PATH_LENGTH UINT64_C(10000)
16 16
17#define FLAG_CUBE "-cube" 17#define FLAG_CUBE "-cube"
18#define FLAG_PERM "-perm"
19#define FLAG_COMMAND "-command" 18#define FLAG_COMMAND "-command"
20#define FLAG_STR_CUBE "-cubestr" 19#define FLAG_STR_CUBE "-cubestr"
21#define FLAG_MOVES "-moves" 20#define FLAG_MOVES "-moves"
@@ -37,7 +36,6 @@
37typedef struct { 36typedef struct {
38 int command_index; 37 int command_index;
39 char cube[NISSY_SIZE_CUBE]; 38 char cube[NISSY_SIZE_CUBE];
40 char cube_perm[NISSY_SIZE_CUBE];
41 char *str_command; 39 char *str_command;
42 char *str_cube; 40 char *str_cube;
43 char *str_moves; 41 char *str_moves;
@@ -51,7 +49,6 @@ typedef struct {
51 unsigned threads; 49 unsigned threads;
52} args_t; 50} args_t;
53 51
54static int64_t compose_exec(args_t *);
55static int64_t inverse_exec(args_t *); 52static int64_t inverse_exec(args_t *);
56static int64_t applymoves_exec(args_t *); 53static int64_t applymoves_exec(args_t *);
57static int64_t applytrans_exec(args_t *); 54static int64_t applytrans_exec(args_t *);
@@ -69,7 +66,6 @@ static bool parse_uint(const char *, unsigned *);
69static uint8_t parse_nisstype(const char *); 66static uint8_t parse_nisstype(const char *);
70 67
71static bool set_cube(int, char **, args_t *); 68static bool set_cube(int, char **, args_t *);
72static bool set_cube_perm(int, char **, args_t *);
73static bool set_str_command(int, char **, args_t *); 69static bool set_str_command(int, char **, args_t *);
74static bool set_str_cube(int, char **, args_t *); 70static bool set_str_cube(int, char **, args_t *);
75static bool set_str_moves(int, char **, args_t *); 71static bool set_str_moves(int, char **, args_t *);
@@ -92,7 +88,6 @@ struct {
92 bool (*set)(int, char **, args_t *); 88 bool (*set)(int, char **, args_t *);
93} options[] = { 89} options[] = {
94 OPTION(FLAG_CUBE, 1, set_cube), 90 OPTION(FLAG_CUBE, 1, set_cube),
95 OPTION(FLAG_PERM, 1, set_cube_perm),
96 OPTION(FLAG_COMMAND, 1, set_str_command), 91 OPTION(FLAG_COMMAND, 1, set_str_command),
97 OPTION(FLAG_STR_CUBE, 1, set_str_cube), 92 OPTION(FLAG_STR_CUBE, 1, set_str_cube),
98 OPTION(FLAG_MOVES, 1, set_str_moves), 93 OPTION(FLAG_MOVES, 1, set_str_moves),
@@ -116,12 +111,6 @@ struct {
116} commands[] = { 111} commands[] = {
117/* TODO: add synopsis and description here */ 112/* TODO: add synopsis and description here */
118 COMMAND( 113 COMMAND(
119 "compose",
120 "compose " FLAG_CUBE " CUBE " FLAG_PERM " PERM",
121 "Apply on CUBE the permutation defined by PERM.",
122 compose_exec
123 ),
124 COMMAND(
125 "inverse", 114 "inverse",
126 "inverse " FLAG_CUBE " CUBE ", 115 "inverse " FLAG_CUBE " CUBE ",
127 "Compute the inverse of the given CUBE.", 116 "Compute the inverse of the given CUBE.",
@@ -224,19 +213,6 @@ rand64(void)
224} 213}
225 214
226static int64_t 215static int64_t
227compose_exec(args_t *args)
228{
229 char result[NISSY_SIZE_CUBE];
230 int64_t ret;
231
232 ret = nissy_compose(args->cube, args->cube_perm, result);
233 if (ret == NISSY_OK || ret == NISSY_WARNING_UNSOLVABLE)
234 printf("%s\n", result);
235
236 return ret;
237}
238
239static int64_t
240inverse_exec(args_t *args) 216inverse_exec(args_t *args)
241{ 217{
242 char result[NISSY_SIZE_CUBE]; 218 char result[NISSY_SIZE_CUBE];
@@ -531,7 +507,6 @@ parse_args(int argc, char **argv, args_t *args)
531 *args = (args_t) { 507 *args = (args_t) {
532 .command_index = -1, 508 .command_index = -1,
533 .cube = "", 509 .cube = "",
534 .cube_perm = "",
535 .str_cube = "", 510 .str_cube = "",
536 .str_moves = "", 511 .str_moves = "",
537 .str_trans = "", 512 .str_trans = "",
@@ -630,15 +605,6 @@ set_cube(int argc, char **argv, args_t *args)
630} 605}
631 606
632static bool 607static bool
633set_cube_perm(int argc, char **argv, args_t *args)
634{
635 memcpy(args->cube_perm, argv[0], NISSY_SIZE_CUBE);
636 args->cube_perm[21] = 0;
637
638 return true;
639}
640
641static bool
642set_str_command(int argc, char **argv, args_t *args) 608set_str_command(int argc, char **argv, args_t *args)
643{ 609{
644 args->str_command = argv[0]; 610 args->str_command = argv[0];
diff --git a/shell/test.sh b/shell/test.sh
deleted file mode 100755
index 8bc4589..0000000
--- a/shell/test.sh
+++ /dev/null
@@ -1,22 +0,0 @@
1#!/bin/sh
2
3SHELLBIN="./debugrun"
4TESTDIR="./shell/testcases"
5TESTOUT="shell/lasttest.out"
6TESTERR="shell/lasttest.err"
7
8for cin in "$TESTDIR"/*.in; do
9 c=$(echo "$cin" | sed 's/\.in//')
10 cout="$c.out"
11 printf "%s: " "$c"
12 (cat "$cin" | xargs "$SHELLBIN") > $TESTOUT 2> $TESTERR
13 if diff "$cout" "$TESTOUT"; then
14 printf "OK\n"
15 else
16 printf "Test failed! stderr:\n"
17 cat $TESTERR
18 exit 1
19 fi
20done
21
22echo "All tests passed!"
diff --git a/shell/testcases/000_frommoves.in b/shell/testcases/000_frommoves.in
deleted file mode 100644
index 2b3c6d1..0000000
--- a/shell/testcases/000_frommoves.in
+++ /dev/null
@@ -1 +0,0 @@
1frommoves -moves "UFRR"
diff --git a/shell/testcases/000_frommoves.out b/shell/testcases/000_frommoves.out
deleted file mode 100644
index dfefe81..0000000
--- a/shell/testcases/000_frommoves.out
+++ /dev/null
@@ -1 +0,0 @@
1DEOISVBH=ZFCYHAGBLTKU
diff --git a/shell/testcases/001_compose.in b/shell/testcases/001_compose.in
deleted file mode 100644
index fa09a0b..0000000
--- a/shell/testcases/001_compose.in
+++ /dev/null
@@ -1 +0,0 @@
1compose -cube NEORSQLH=ZFCYUAGLHTKB -perm NEORSQLH=ZFCYUAGLHTKB
diff --git a/shell/testcases/001_compose.out b/shell/testcases/001_compose.out
deleted file mode 100644
index d36a93c..0000000
--- a/shell/testcases/001_compose.out
+++ /dev/null
@@ -1 +0,0 @@
1ASTUGFBH=DACXEZGBLIKF
diff --git a/src/nissy.c b/src/nissy.c
index 8aa0334..bf56f40 100644
--- a/src/nissy.c
+++ b/src/nissy.c
@@ -142,47 +142,6 @@ my_strnlen(const char *str, size_t maxlen)
142} 142}
143 143
144long long 144long long
145nissy_compose(
146 const char cube[static NISSY_SIZE_CUBE],
147 const char permutation[static NISSY_SIZE_CUBE],
148 char result[static NISSY_SIZE_CUBE]
149)
150{
151 cube_t c, p, res;
152 long long err;
153
154 c = readcube(cube);
155
156 if (!isconsistent(c)) {
157 LOG("[compose] Error: the given cube is invalid\n");
158 err = NISSY_ERROR_INVALID_CUBE;
159 goto nissy_compose_error;
160 }
161
162 p = readcube(permutation);
163
164 if (!isconsistent(p)) {
165 LOG("[compose] Error: given permutation is invalid\n");
166 err = NISSY_ERROR_INVALID_CUBE;
167 goto nissy_compose_error;
168 }
169
170 res = compose(c, p);
171
172 if (!isconsistent(res)) {
173 LOG("[compose] Unknown error: resulting cube is invalid\n");
174 err = NISSY_ERROR_UNKNOWN;
175 goto nissy_compose_error;
176 }
177
178 return write_result(res, result);
179
180nissy_compose_error:
181 writecube(ZERO_CUBE, NISSY_SIZE_CUBE, result);
182 return err;
183}
184
185long long
186nissy_inverse( 145nissy_inverse(
187 const char cube[static NISSY_SIZE_CUBE], 146 const char cube[static NISSY_SIZE_CUBE],
188 char result[static NISSY_SIZE_CUBE] 147 char result[static NISSY_SIZE_CUBE]
diff --git a/src/nissy.h b/src/nissy.h
index 4b2d1eb..e7ae50e 100644
--- a/src/nissy.h
+++ b/src/nissy.h
@@ -126,31 +126,6 @@ of this kind to sebastiano@tronto.net. Thanks!
126/* Library functions *********************************************************/ 126/* Library functions *********************************************************/
127 127
128/* 128/*
129Apply the secod argument as a permutation on the first argument.
130
131Parameters:
132 cube - The first cube.
133 permutation - The second cub. This cube is treated as a permutation and
134 "applied" to the first cube.
135 result - The return parameter for the resulting cube.
136
137Return values:
138 NISSY_OK - The cubes were composed succesfully.
139 NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is
140 either because at least on of the given cubes
141 was not solvable, or due to an unknown internal
142 error.
143 NISSY_ERROR_INVALID_CUBE - At least one of the given cubes is invalid.
144 NISSY_ERROR_UNKNOWN - An unknown error occurred.
145*/
146long long
147nissy_compose(
148 const char cube[static NISSY_SIZE_CUBE],
149 const char permutation[static NISSY_SIZE_CUBE],
150 char result[static NISSY_SIZE_CUBE]
151);
152
153/*
154Compute the inverse of the given cube. 129Compute the inverse of the given cube.
155 130
156Parameters: 131Parameters:

Generated with cgit - Back to sebastiano.tronto.net