diff options
| author | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-27 16:53:22 +0100 |
|---|---|---|
| committer | Sebastiano Tronto <sebastiano@tronto.net> | 2022-02-27 16:53:22 +0100 |
| commit | 7de88d1bcd420447023b8e74b0aa4f5e8ba1df6b (patch) | |
| tree | 71458dbc99241c9d56744508996d68099bf01936 | |
| parent | 48cd8b6b1779f34ba0507cb697492de83c4e9da8 (diff) | |
| download | nissy-7de88d1bcd420447023b8e74b0aa4f5e8ba1df6b.tar.gz nissy-7de88d1bcd420447023b8e74b0aa4f5e8ba1df6b.zip | |
Removed array-size constants for certain objects (steps, commands...)
| -rw-r--r-- | TODO.md | 5 | ||||
| -rwxr-xr-x | nissy | bin | 0 -> 326824 bytes | |||
| -rw-r--r-- | src/commands.c | 18 | ||||
| -rw-r--r-- | src/commands.h | 4 | ||||
| -rw-r--r-- | src/pruning.c | 3 | ||||
| -rw-r--r-- | src/pruning.h | 4 | ||||
| -rw-r--r-- | src/shell.c | 4 | ||||
| -rw-r--r-- | src/steps.c | 4 | ||||
| -rw-r--r-- | src/steps.h | 48 |
9 files changed, 24 insertions, 66 deletions
| @@ -56,6 +56,10 @@ including e.g. solutions that were not shown because -c) | |||
| 56 | ## Technical stuff | 56 | ## Technical stuff |
| 57 | 57 | ||
| 58 | ### Memory management | 58 | ### Memory management |
| 59 | * Optimization: allow coordinates do define how moves and trans are applied on | ||
| 60 | them; if not then just move the cube normally. | ||
| 61 | This can speedup things, for example in computing coordinates (no need to apply | ||
| 62 | trans_to_rep) and of course in optimal solver. | ||
| 59 | * free pruning table after solve is done? if I do this I need to deafault to a | 63 | * free pruning table after solve is done? if I do this I need to deafault to a |
| 60 | small table for < 8 moves solutions or smth | 64 | small table for < 8 moves solutions or smth |
| 61 | * improve multi-threading when solving multiple scrambles | 65 | * improve multi-threading when solving multiple scrambles |
| @@ -86,7 +90,6 @@ including e.g. solutions that were not shown because -c) | |||
| 86 | 90 | ||
| 87 | ### Cleanup | 91 | ### Cleanup |
| 88 | * Remove khuge from everywhere | 92 | * Remove khuge from everywhere |
| 89 | * Arrays (commands, steps...): end with NULL and remove size constant | ||
| 90 | * sort again functions alphabetically in their files | 93 | * sort again functions alphabetically in their files |
| 91 | * more stuff to load at start (or when suitable command is called) rather | 94 | * more stuff to load at start (or when suitable command is called) rather |
| 92 | than when called directly, to avoid nasty problems with threading | 95 | than when called directly, to avoid nasty problems with threading |
| Binary files differ | |||
diff --git a/src/commands.c b/src/commands.c index b397878..03eded0 100644 --- a/src/commands.c +++ b/src/commands.c | |||
| @@ -150,7 +150,7 @@ version_cmd = { | |||
| 150 | .exec = version_exec, | 150 | .exec = version_exec, |
| 151 | }; | 151 | }; |
| 152 | 152 | ||
| 153 | Command *commands[NCOMMANDS] = { | 153 | Command *commands[] = { |
| 154 | &commands_cmd, | 154 | &commands_cmd, |
| 155 | &gen_cmd, | 155 | &gen_cmd, |
| 156 | &help_cmd, | 156 | &help_cmd, |
| @@ -164,6 +164,7 @@ Command *commands[NCOMMANDS] = { | |||
| 164 | &cleanup_cmd, | 164 | &cleanup_cmd, |
| 165 | &unniss_cmd, | 165 | &unniss_cmd, |
| 166 | &version_cmd, | 166 | &version_cmd, |
| 167 | NULL | ||
| 167 | }; | 168 | }; |
| 168 | 169 | ||
| 169 | /* Other constants ***********************************************************/ | 170 | /* Other constants ***********************************************************/ |
| @@ -336,9 +337,8 @@ help_parse_args(int c, char **v) | |||
| 336 | CommandArgs *a = new_args(); | 337 | CommandArgs *a = new_args(); |
| 337 | 338 | ||
| 338 | if (c == 1) { | 339 | if (c == 1) { |
| 339 | for (i = 0; i < NCOMMANDS; i++) | 340 | for (i = 0; commands[i] != NULL; i++) |
| 340 | if (commands[i] != NULL && | 341 | if (!strcmp(v[0], commands[i]->name)) |
| 341 | !strcmp(v[0], commands[i]->name)) | ||
| 342 | a->command = commands[i]; | 342 | a->command = commands[i]; |
| 343 | if (a->command == NULL) | 343 | if (a->command == NULL) |
| 344 | fprintf(stderr, "%s: command not found\n", v[0]); | 344 | fprintf(stderr, "%s: command not found\n", v[0]); |
| @@ -473,7 +473,7 @@ gen_exec(CommandArgs *args) | |||
| 473 | init_symcoord(); | 473 | init_symcoord(); |
| 474 | 474 | ||
| 475 | fprintf(stderr, "Generating pruning tables...\n"); | 475 | fprintf(stderr, "Generating pruning tables...\n"); |
| 476 | for (i = 0; i < NPTABLES && allpd[i] != NULL; i++) | 476 | for (i = 0; allpd[i] != NULL; i++) |
| 477 | genptable(allpd[i], args->opts->nthreads); | 477 | genptable(allpd[i], args->opts->nthreads); |
| 478 | 478 | ||
| 479 | fprintf(stderr, "Done!\n"); | 479 | fprintf(stderr, "Done!\n"); |
| @@ -495,7 +495,7 @@ steps_exec(CommandArgs *args) | |||
| 495 | { | 495 | { |
| 496 | int i; | 496 | int i; |
| 497 | 497 | ||
| 498 | for (i = 0; i < NSTEPS && steps[i] != NULL; i++) | 498 | for (i = 0; steps[i] != NULL; i++) |
| 499 | printf("%-15s %s\n", steps[i]->shortname, steps[i]->name); | 499 | printf("%-15s %s\n", steps[i]->shortname, steps[i]->name); |
| 500 | } | 500 | } |
| 501 | 501 | ||
| @@ -504,7 +504,7 @@ commands_exec(CommandArgs *args) | |||
| 504 | { | 504 | { |
| 505 | int i; | 505 | int i; |
| 506 | 506 | ||
| 507 | for (i = 0; i < NCOMMANDS && commands[i] != NULL; i++) | 507 | for (i = 0; commands[i] != NULL; i++) |
| 508 | printf("%s\n", commands[i]->usage); | 508 | printf("%s\n", commands[i]->usage); |
| 509 | 509 | ||
| 510 | } | 510 | } |
| @@ -642,8 +642,8 @@ read_step(CommandArgs *args, char *str) | |||
| 642 | { | 642 | { |
| 643 | int i; | 643 | int i; |
| 644 | 644 | ||
| 645 | for (i = 0; i < NSTEPS; i++) { | 645 | for (i = 0; steps[i] != NULL; i++) { |
| 646 | if (steps[i] != NULL && !strcmp(steps[i]->shortname, str)) { | 646 | if (!strcmp(steps[i]->shortname, str)) { |
| 647 | args->step = steps[i]; | 647 | args->step = steps[i]; |
| 648 | return true; | 648 | return true; |
| 649 | } | 649 | } |
diff --git a/src/commands.h b/src/commands.h index bac71f1..b7a4c36 100644 --- a/src/commands.h +++ b/src/commands.h | |||
| @@ -6,11 +6,9 @@ | |||
| 6 | #include "solve.h" | 6 | #include "solve.h" |
| 7 | #include "steps.h" | 7 | #include "steps.h" |
| 8 | 8 | ||
| 9 | #define NCOMMANDS 20 | ||
| 10 | |||
| 11 | void free_args(CommandArgs *args); | 9 | void free_args(CommandArgs *args); |
| 12 | CommandArgs * new_args(); | 10 | CommandArgs * new_args(); |
| 13 | 11 | ||
| 14 | extern Command * commands[NCOMMANDS]; | 12 | extern Command * commands[]; |
| 15 | 13 | ||
| 16 | #endif | 14 | #endif |
diff --git a/src/pruning.c b/src/pruning.c index e6fd791..51bea10 100644 --- a/src/pruning.c +++ b/src/pruning.c | |||
| @@ -98,7 +98,7 @@ pd_nxopt31_HTM = { | |||
| 98 | .fbmod = BINOM8ON4, | 98 | .fbmod = BINOM8ON4, |
| 99 | }; | 99 | }; |
| 100 | 100 | ||
| 101 | PruneData * allpd[NPTABLES] = { | 101 | PruneData * allpd[] = { |
| 102 | &pd_eofb_HTM, | 102 | &pd_eofb_HTM, |
| 103 | &pd_coud_HTM, | 103 | &pd_coud_HTM, |
| 104 | &pd_cornershtr_HTM, | 104 | &pd_cornershtr_HTM, |
| @@ -110,6 +110,7 @@ PruneData * allpd[NPTABLES] = { | |||
| 110 | &pd_htrfin_htr, | 110 | &pd_htrfin_htr, |
| 111 | /* &pd_khuge_HTM,*/ | 111 | /* &pd_khuge_HTM,*/ |
| 112 | &pd_nxopt31_HTM, | 112 | &pd_nxopt31_HTM, |
| 113 | NULL | ||
| 113 | }; | 114 | }; |
| 114 | 115 | ||
| 115 | /* Functions *****************************************************************/ | 116 | /* Functions *****************************************************************/ |
diff --git a/src/pruning.h b/src/pruning.h index 0f20384..7da1e3e 100644 --- a/src/pruning.h +++ b/src/pruning.h | |||
| @@ -3,8 +3,6 @@ | |||
| 3 | 3 | ||
| 4 | #include "symcoord.h" | 4 | #include "symcoord.h" |
| 5 | 5 | ||
| 6 | #define NPTABLES 20 | ||
| 7 | |||
| 8 | extern PruneData pd_eofb_HTM; | 6 | extern PruneData pd_eofb_HTM; |
| 9 | extern PruneData pd_coud_HTM; | 7 | extern PruneData pd_coud_HTM; |
| 10 | extern PruneData pd_corners_HTM; | 8 | extern PruneData pd_corners_HTM; |
| @@ -17,7 +15,7 @@ extern PruneData pd_htrfin_htr; | |||
| 17 | extern PruneData pd_khuge_HTM; | 15 | extern PruneData pd_khuge_HTM; |
| 18 | extern PruneData pd_nxopt31_HTM; | 16 | extern PruneData pd_nxopt31_HTM; |
| 19 | 17 | ||
| 20 | extern PruneData * allpd[NPTABLES]; | 18 | extern PruneData * allpd[]; |
| 21 | 19 | ||
| 22 | void genptable(PruneData *pd, int nthreads); | 20 | void genptable(PruneData *pd, int nthreads); |
| 23 | void print_ptable(PruneData *pd); | 21 | void print_ptable(PruneData *pd); |
diff --git a/src/shell.c b/src/shell.c index 2cb3719..6e67e0a 100644 --- a/src/shell.c +++ b/src/shell.c | |||
| @@ -37,8 +37,8 @@ exec_args(int c, char **v) | |||
| 37 | CommandArgs *args; | 37 | CommandArgs *args; |
| 38 | Alg *scramble; | 38 | Alg *scramble; |
| 39 | 39 | ||
| 40 | for (i = 0; i < NCOMMANDS; i++) | 40 | for (i = 0; commands[i] != NULL; i++) |
| 41 | if (commands[i] != NULL && !strcmp(v[0], commands[i]->name)) | 41 | if (!strcmp(v[0], commands[i]->name)) |
| 42 | cmd = commands[i]; | 42 | cmd = commands[i]; |
| 43 | 43 | ||
| 44 | if (cmd == NULL) { | 44 | if (cmd == NULL) { |
diff --git a/src/steps.c b/src/steps.c index 5de3206..83d105c 100644 --- a/src/steps.c +++ b/src/steps.c | |||
| @@ -929,7 +929,7 @@ htrfin_htr = { | |||
| 929 | .ntables = 1, | 929 | .ntables = 1, |
| 930 | }; | 930 | }; |
| 931 | 931 | ||
| 932 | Step *steps[NSTEPS] = { | 932 | Step *steps[] = { |
| 933 | &optimal_HTM, /* first is default */ | 933 | &optimal_HTM, /* first is default */ |
| 934 | &optimal_light_HTM, | 934 | &optimal_light_HTM, |
| 935 | 935 | ||
| @@ -985,6 +985,8 @@ Step *steps[NSTEPS] = { | |||
| 985 | &cornershtr_URF, | 985 | &cornershtr_URF, |
| 986 | &corners_HTM, | 986 | &corners_HTM, |
| 987 | &corners_URF, | 987 | &corners_URF, |
| 988 | |||
| 989 | NULL | ||
| 988 | }; | 990 | }; |
| 989 | 991 | ||
| 990 | /* Checkers, estimators and validators ***************************************/ | 992 | /* Checkers, estimators and validators ***************************************/ |
diff --git a/src/steps.h b/src/steps.h index 53f8e1b..da5c041 100644 --- a/src/steps.h +++ b/src/steps.h | |||
| @@ -3,55 +3,11 @@ | |||
| 3 | 3 | ||
| 4 | #include "pruning.h" | 4 | #include "pruning.h" |
| 5 | 5 | ||
| 6 | #define NSTEPS 50 | 6 | extern Step * steps[]; |
| 7 | 7 | ||
| 8 | extern Step * steps[NSTEPS]; | 8 | /* Two steps used directly by two-phase solver */ |
| 9 | |||
| 10 | extern Step optimal_HTM; | ||
| 11 | extern Step optimal_light_HTM; | ||
| 12 | extern Step eofin_eo; | ||
| 13 | extern Step eofbfin_eofb; | ||
| 14 | extern Step eorlfin_eorl; | ||
| 15 | extern Step eoudfin_eoud; | ||
| 16 | extern Step eoany_HTM; | ||
| 17 | extern Step eofb_HTM; | ||
| 18 | extern Step eorl_HTM; | ||
| 19 | extern Step eoud_HTM; | ||
| 20 | extern Step coany_HTM; | ||
| 21 | extern Step coud_HTM; | ||
| 22 | extern Step corl_HTM; | ||
| 23 | extern Step cofb_HTM; | ||
| 24 | extern Step coany_URF; | ||
| 25 | extern Step coud_URF; | ||
| 26 | extern Step corl_URF; | ||
| 27 | extern Step cofb_URF; | ||
| 28 | extern Step drany_HTM; | 9 | extern Step drany_HTM; |
| 29 | extern Step drud_HTM; | ||
| 30 | extern Step drrl_HTM; | ||
| 31 | extern Step drfb_HTM; | ||
| 32 | extern Step dr_eo; | ||
| 33 | extern Step dr_eofb; | ||
| 34 | extern Step dr_eorl; | ||
| 35 | extern Step dr_eoud; | ||
| 36 | extern Step drud_eofb; | ||
| 37 | extern Step drrl_eofb; | ||
| 38 | extern Step drud_eorl; | ||
| 39 | extern Step drfb_eorl; | ||
| 40 | extern Step drfb_eoud; | ||
| 41 | extern Step drrl_eoud; | ||
| 42 | extern Step dranyfin_DR; | 10 | extern Step dranyfin_DR; |
| 43 | extern Step drudfin_drud; | ||
| 44 | extern Step drrlfin_drrl; | ||
| 45 | extern Step drfbfin_drfb; | ||
| 46 | extern Step htr_any; | ||
| 47 | extern Step htr_drud; | ||
| 48 | extern Step htr_drrl; | ||
| 49 | extern Step htr_drfb; | ||
| 50 | extern Step htrfin_htr; | ||
| 51 | extern Step cornershtr_HTM; | ||
| 52 | extern Step cornershtr_URF; | ||
| 53 | extern Step corners_HTM; | ||
| 54 | extern Step corners_URF; | ||
| 55 | 11 | ||
| 56 | void copy_estimatedata(EstimateData *s, EstimateData *d); | 12 | void copy_estimatedata(EstimateData *s, EstimateData *d); |
| 57 | void invert_estimatedata(EstimateData *ed); | 13 | void invert_estimatedata(EstimateData *ed); |
