From 93522effba2f200257141189de5925a23fca93b8 Mon Sep 17 00:00:00 2001 From: Sebastiano Tronto Date: Tue, 22 Apr 2025 14:47:25 +0200 Subject: Remove compose from the public API --- README.md | 4 ++-- cpp/nissy.cpp | 9 --------- cpp/nissy.h | 1 - python/nissy_module.c | 27 -------------------------- shell/shell.c | 34 -------------------------------- shell/test.sh | 22 --------------------- shell/testcases/000_frommoves.in | 1 - shell/testcases/000_frommoves.out | 1 - shell/testcases/001_compose.in | 1 - shell/testcases/001_compose.out | 1 - src/nissy.c | 41 --------------------------------------- src/nissy.h | 25 ------------------------ 12 files changed, 2 insertions(+), 165 deletions(-) delete mode 100755 shell/test.sh delete mode 100644 shell/testcases/000_frommoves.in delete mode 100644 shell/testcases/000_frommoves.out delete mode 100644 shell/testcases/001_compose.in delete mode 100644 shell/testcases/001_compose.out 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 From here you can call the library functions directly, for example: ``` ->>> nissy.compose('NEORSQLH=ZFCYUAGLHTKB=A', 'NEORSQLH=ZFCYUAGLHTKB=A') -'ASTUGFBH=DACXEZGBLIKF=A' +>>> nissy.applymoves('ABCDEFGH=ABCDEFGHIJKL=A', "R U R' U'") +'WFCDERQH=AECDIFGHBJKL=A' ``` The `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) #include extern "C" { - long long nissy_compose(const char *, const char *, char *); long long nissy_inverse(const char *, char *); long long nissy_applymoves(const char *, const char *, char *); long long nissy_applytrans(const char *, const char *, char *); @@ -87,14 +86,6 @@ namespace nissy { m_str = result; } - void cube::compose(const cube& other) - { - char result[size::CUBE]; - nissy_compose( - m_str.c_str(), other.to_string().c_str(), result); - m_str = result; - } - std::string cube::to_string() const { return m_str; } std::variant 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 { error move(const std::string&); error transform(const std::string&); void invert(); - void compose(const cube&); std::string to_string() const; static std::variant 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) return PyLong_FromLong(result); } - -PyDoc_STRVAR(compose_doc, -"compose(cube, permutation)\n" -"--\n\n" -"Apply 'permutation' on 'cube'.\n" -"\n" -"Parameters:\n" -" - cube: a cube\n" -" - permutation: another cube\n" -"\n" -"Returns: the resulting cube string\n" -); -static PyObject * -compose(PyObject *self, PyObject *args) -{ - long long err; - const char *cube, *permutation; - char result[NISSY_SIZE_CUBE]; - - if (!PyArg_ParseTuple(args, "ss", &cube, &permutation)) - return NULL; - - err = nissy_compose(cube, permutation, result); - return string_result(err, result); -} - PyDoc_STRVAR(inverse_doc, "inverse(cube)\n" "--\n\n" @@ -368,7 +342,6 @@ countmoves(PyObject *self, PyObject *args) } static PyMethodDef nissy_methods[] = { - { "compose", compose, METH_VARARGS, compose_doc }, { "inverse", inverse, METH_VARARGS, inverse_doc }, { "applymoves", applymoves, METH_VARARGS, applymoves_doc }, { "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 @@ #define MAX_PATH_LENGTH UINT64_C(10000) #define FLAG_CUBE "-cube" -#define FLAG_PERM "-perm" #define FLAG_COMMAND "-command" #define FLAG_STR_CUBE "-cubestr" #define FLAG_MOVES "-moves" @@ -37,7 +36,6 @@ typedef struct { int command_index; char cube[NISSY_SIZE_CUBE]; - char cube_perm[NISSY_SIZE_CUBE]; char *str_command; char *str_cube; char *str_moves; @@ -51,7 +49,6 @@ typedef struct { unsigned threads; } args_t; -static int64_t compose_exec(args_t *); static int64_t inverse_exec(args_t *); static int64_t applymoves_exec(args_t *); static int64_t applytrans_exec(args_t *); @@ -69,7 +66,6 @@ static bool parse_uint(const char *, unsigned *); static uint8_t parse_nisstype(const char *); static bool set_cube(int, char **, args_t *); -static bool set_cube_perm(int, char **, args_t *); static bool set_str_command(int, char **, args_t *); static bool set_str_cube(int, char **, args_t *); static bool set_str_moves(int, char **, args_t *); @@ -92,7 +88,6 @@ struct { bool (*set)(int, char **, args_t *); } options[] = { OPTION(FLAG_CUBE, 1, set_cube), - OPTION(FLAG_PERM, 1, set_cube_perm), OPTION(FLAG_COMMAND, 1, set_str_command), OPTION(FLAG_STR_CUBE, 1, set_str_cube), OPTION(FLAG_MOVES, 1, set_str_moves), @@ -115,12 +110,6 @@ struct { int64_t (*exec)(args_t *); } commands[] = { /* TODO: add synopsis and description here */ - COMMAND( - "compose", - "compose " FLAG_CUBE " CUBE " FLAG_PERM " PERM", - "Apply on CUBE the permutation defined by PERM.", - compose_exec - ), COMMAND( "inverse", "inverse " FLAG_CUBE " CUBE ", @@ -223,19 +212,6 @@ rand64(void) return ret; } -static int64_t -compose_exec(args_t *args) -{ - char result[NISSY_SIZE_CUBE]; - int64_t ret; - - ret = nissy_compose(args->cube, args->cube_perm, result); - if (ret == NISSY_OK || ret == NISSY_WARNING_UNSOLVABLE) - printf("%s\n", result); - - return ret; -} - static int64_t inverse_exec(args_t *args) { @@ -531,7 +507,6 @@ parse_args(int argc, char **argv, args_t *args) *args = (args_t) { .command_index = -1, .cube = "", - .cube_perm = "", .str_cube = "", .str_moves = "", .str_trans = "", @@ -629,15 +604,6 @@ set_cube(int argc, char **argv, args_t *args) return true; } -static bool -set_cube_perm(int argc, char **argv, args_t *args) -{ - memcpy(args->cube_perm, argv[0], NISSY_SIZE_CUBE); - args->cube_perm[21] = 0; - - return true; -} - static bool set_str_command(int argc, char **argv, args_t *args) { 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 @@ -#!/bin/sh - -SHELLBIN="./debugrun" -TESTDIR="./shell/testcases" -TESTOUT="shell/lasttest.out" -TESTERR="shell/lasttest.err" - -for cin in "$TESTDIR"/*.in; do - c=$(echo "$cin" | sed 's/\.in//') - cout="$c.out" - printf "%s: " "$c" - (cat "$cin" | xargs "$SHELLBIN") > $TESTOUT 2> $TESTERR - if diff "$cout" "$TESTOUT"; then - printf "OK\n" - else - printf "Test failed! stderr:\n" - cat $TESTERR - exit 1 - fi -done - -echo "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 @@ -frommoves -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 @@ -DEOISVBH=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 @@ -compose -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 @@ -ASTUGFBH=DACXEZGBLIKF diff --git a/src/nissy.c b/src/nissy.c index 8aa0334..bf56f40 100644 --- a/src/nissy.c +++ b/src/nissy.c @@ -141,47 +141,6 @@ my_strnlen(const char *str, size_t maxlen) return maxlen; } -long long -nissy_compose( - const char cube[static NISSY_SIZE_CUBE], - const char permutation[static NISSY_SIZE_CUBE], - char result[static NISSY_SIZE_CUBE] -) -{ - cube_t c, p, res; - long long err; - - c = readcube(cube); - - if (!isconsistent(c)) { - LOG("[compose] Error: the given cube is invalid\n"); - err = NISSY_ERROR_INVALID_CUBE; - goto nissy_compose_error; - } - - p = readcube(permutation); - - if (!isconsistent(p)) { - LOG("[compose] Error: given permutation is invalid\n"); - err = NISSY_ERROR_INVALID_CUBE; - goto nissy_compose_error; - } - - res = compose(c, p); - - if (!isconsistent(res)) { - LOG("[compose] Unknown error: resulting cube is invalid\n"); - err = NISSY_ERROR_UNKNOWN; - goto nissy_compose_error; - } - - return write_result(res, result); - -nissy_compose_error: - writecube(ZERO_CUBE, NISSY_SIZE_CUBE, result); - return err; -} - long long nissy_inverse( const char cube[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 @@ -125,31 +125,6 @@ of this kind to sebastiano@tronto.net. Thanks! /* Library functions *********************************************************/ -/* -Apply the secod argument as a permutation on the first argument. - -Parameters: - cube - The first cube. - permutation - The second cub. This cube is treated as a permutation and - "applied" to the first cube. - result - The return parameter for the resulting cube. - -Return values: - NISSY_OK - The cubes were composed succesfully. - NISSY_WARNING_UNSOLVABLE - The resulting cube is not solvable. This is - either because at least on of the given cubes - was not solvable, or due to an unknown internal - error. - NISSY_ERROR_INVALID_CUBE - At least one of the given cubes is invalid. - NISSY_ERROR_UNKNOWN - An unknown error occurred. -*/ -long long -nissy_compose( - const char cube[static NISSY_SIZE_CUBE], - const char permutation[static NISSY_SIZE_CUBE], - char result[static NISSY_SIZE_CUBE] -); - /* Compute the inverse of the given cube. -- cgit v1.3