commit 93522effba2f200257141189de5925a23fca93b8
parent 1fb55fe25b3dd5ef61dbc38290fbba2e233dc6b6
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date: Tue, 22 Apr 2025 14:47:25 +0200
Remove compose from the public API
Diffstat:
12 files changed, 2 insertions(+), 165 deletions(-)
diff --git 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
@@ -9,7 +9,6 @@ TODO: add more documentation (here and in README.md)
#include <fstream>
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<cube, error>
diff --git 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<cube, error> from_string(
diff --git 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
@@ -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),
@@ -116,12 +111,6 @@ struct {
} 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 ",
"Compute the inverse of the given CUBE.",
@@ -224,19 +213,6 @@ rand64(void)
}
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)
{
char result[NISSY_SIZE_CUBE];
@@ -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 = "",
@@ -630,15 +605,6 @@ set_cube(int argc, char **argv, args_t *args)
}
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)
{
args->str_command = argv[0];
diff --git a/shell/test.sh b/shell/test.sh
@@ -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
@@ -1 +0,0 @@
-frommoves -moves "UFRR"
diff --git a/shell/testcases/000_frommoves.out b/shell/testcases/000_frommoves.out
@@ -1 +0,0 @@
-DEOISVBH=ZFCYHAGBLTKU
diff --git a/shell/testcases/001_compose.in b/shell/testcases/001_compose.in
@@ -1 +0,0 @@
-compose -cube NEORSQLH=ZFCYUAGLHTKB -perm NEORSQLH=ZFCYUAGLHTKB
diff --git a/shell/testcases/001_compose.out b/shell/testcases/001_compose.out
@@ -1 +0,0 @@
-ASTUGFBH=DACXEZGBLIKF
diff --git a/src/nissy.c b/src/nissy.c
@@ -142,47 +142,6 @@ my_strnlen(const char *str, size_t 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],
char result[static NISSY_SIZE_CUBE]
diff --git a/src/nissy.h b/src/nissy.h
@@ -126,31 +126,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.
Parameters: