nissy-classic

Stable branch of nissy
git clone https://git.tronto.net/nissy-classic
Download | Log | Files | Refs | README | LICENSE

commit db4d88428a1bf20652f11d4cf9b31b7114fdacfb
parent 9c78331ef2ebe2f1dcef886b0043431469bc1a29
Author: Sebastiano Tronto <sebastiano@tronto.net>
Date:   Thu, 21 Sep 2023 22:36:36 +0200

Added ptable command

Diffstat:
M.gitignore | 1+
Mdoc/nissy.1 | 7+++++++
Msrc/commands.c | 48++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/cubetypes.h | 1+
Msrc/pruning.c | 5++++-
5 files changed, 61 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore @@ -1,4 +1,5 @@ doc/*.html doc/*.pdf +experiments nissy nissy-* diff --git a/doc/nissy.1 b/doc/nissy.1 @@ -81,6 +81,13 @@ Invert the given scramble. Display a text-only description of the cube obtained after applying .Ar scramble . . +.It Nm ptable Op Ar table +Display information, such as the table distribution, on a pruning table. +If no +.Ar table +is given, the available pruning tables are listed. +This command is intended for advanced use only. +. .It Nm quit Quit nissy. . diff --git a/src/commands.c b/src/commands.c @@ -6,6 +6,7 @@ CommandArgs * gen_parse_args(int c, char **v); CommandArgs * help_parse_args(int c, char **v); CommandArgs * parse_only_scramble(int c, char **v); CommandArgs * parse_no_arg(int c, char **v); +CommandArgs * ptable_parse_args(int c, char **v); CommandArgs * solve_parse_args(int c, char **v); CommandArgs * scramble_parse_args(int c, char **v); @@ -20,6 +21,7 @@ static void steps_exec(CommandArgs *args); static void commands_exec(CommandArgs *args); static void freemem_exec(CommandArgs *args); static void print_exec(CommandArgs *args); +static void ptable_exec(CommandArgs *args); static void twophase_exec(CommandArgs *args); static void help_exec(CommandArgs *args); static void quit_exec(CommandArgs *args); @@ -107,6 +109,15 @@ print_cmd = { }; Command +ptable_cmd = { + .name = "ptable", + .usage = "ptable [TABLE]", + .description = "Print information on pruning tables", + .parse_args = ptable_parse_args, + .exec = ptable_exec, +}; + +Command help_cmd = { .name = "help", .usage = "help [COMMAND]", @@ -167,6 +178,7 @@ Command *commands[] = { &help_cmd, &invert_cmd, &print_cmd, + &ptable_cmd, &quit_cmd, &solve_cmd, &scramble_cmd, @@ -384,6 +396,24 @@ parse_no_arg(int c, char **v) return a; } +CommandArgs * +ptable_parse_args(int c, char **v) +{ + int i; + CommandArgs *a = new_args(); + + if (c == 1) { + for (i = 0; all_pd[i] != NULL; i++) + if (!strcmp(v[0], all_pd[i]->filename)) + a->pd = all_pd[i]; + if (a->pd == NULL) + fprintf(stderr, "%s: pruning table not found\n", v[0]); + } + + a->success = c == 0 || (c == 1 && a->pd != NULL); + return a; +} + /* Exec functions implementation *********************************************/ static void @@ -584,6 +614,23 @@ print_exec(CommandArgs *args) } static void +ptable_exec(CommandArgs *args) +{ + int i = 0; + if (args->pd == NULL) { + printf("Available pruning tables:\n"); + for (i = 0; all_pd[i] != NULL; i++) + printf("\t%s\n", all_pd[i]->filename); + printf("Use ptable [TABLE] to see the table distribution" + " and other information\n"); + } else { + genptable(args->pd, args->opts->nthreads); + print_ptable(args->pd); + } +} + + +static void twophase_exec(CommandArgs *args) { Cube c; @@ -750,6 +797,7 @@ new_args(void) /* step and command are static */ args->step = steps[0]; /* default: first step in list */ args->command = NULL; + args->pd = NULL; return args; } diff --git a/src/cubetypes.h b/src/cubetypes.h @@ -162,6 +162,7 @@ commandargs char scrtype[20]; bool scrstdin; bool header; + PruneData * pd; }; struct diff --git a/src/pruning.c b/src/pruning.c @@ -405,7 +405,10 @@ print_ptable(PruneData *pd) printf("Table %s\n", pd->filename); printf("Base value: %d\n", pd->base); for (i = 0; i < 16; i++) - printf("%2" PRIu64 "\t%10" PRIu64 "\n", i, pd->count[i]); + if (pd->count[i] != 0) + printf("%2" PRIu64 "\t%10" PRIu64 "\n", + i, pd->count[i]); + printf("Total: %" PRIu64 "\n", pd->coord->max); } uint64_t