aboutsummaryrefslogtreecommitdiff
path: root/src/exhaustive
diff options
context:
space:
mode:
authorJ08nY2017-04-05 00:18:01 +0200
committerJ08nY2017-04-05 00:23:33 +0200
commitf87dd8a285755f9b1d838b3efdfd952fae81ee55 (patch)
tree07916d786c9c68e8020e4ee969b328d19eebbc0f /src/exhaustive
parentb77fd8c4eb3f1dba399d8451909fefc52b436c35 (diff)
downloadecgen-f87dd8a285755f9b1d838b3efdfd952fae81ee55.tar.gz
ecgen-f87dd8a285755f9b1d838b3efdfd952fae81ee55.tar.zst
ecgen-f87dd8a285755f9b1d838b3efdfd952fae81ee55.zip
Add exhaustive_gen_retry, fix infinite loop, add retry limit to exhaustive gen
Diffstat (limited to 'src/exhaustive')
-rw-r--r--src/exhaustive/exhaustive.c34
-rw-r--r--src/exhaustive/exhaustive.h15
2 files changed, 42 insertions, 7 deletions
diff --git a/src/exhaustive/exhaustive.c b/src/exhaustive/exhaustive.c
index 3b16349..42c174f 100644
--- a/src/exhaustive/exhaustive.c
+++ b/src/exhaustive/exhaustive.c
@@ -99,15 +99,19 @@ void exhaustive_ainit(arg_t **argss, config_t *cfg) {
}
}
-int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[],
- arg_t *argss[], int start_offset, int end_offset) {
+int exhaustive_gen_retry(curve_t *curve, config_t *cfg, gen_t generators[],
+ arg_t *argss[], int start_offset, int end_offset,
+ int retry) {
if (start_offset == end_offset) {
return 1;
}
if (start_offset > end_offset) {
- return 0;
+ return -1;
}
- pari_sp tops[end_offset - start_offset];
+ int num_gens = end_offset - start_offset;
+ pari_sp tops[num_gens];
+ int tries[num_gens];
+ memset(tries, 0, sizeof(int) * num_gens);
int state = start_offset;
while (state < end_offset) {
@@ -115,9 +119,19 @@ int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[],
int diff = generators[state](curve, cfg, argss ? argss[state] : NULL);
if (diff == INT_MIN) {
- fprintf(stderr, "Error generating a curve. %i\n", state);
+ fprintf(stderr, "Error generating a curve. state = %i\n", state);
return 0;
}
+ if (diff == 0) {
+ int tried = ++tries[state - start_offset];
+ if (retry && tried >= retry) {
+ fprintf(stderr, "Reached retry limit: %i, state = %i\n", retry,
+ state);
+ return 0;
+ }
+ } else if (diff > 0) {
+ tries[state - start_offset] = 0;
+ }
state += diff;
if (diff <= 0) {
@@ -141,6 +155,12 @@ int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[],
return 1;
}
+int exhaustive_gen(curve_t *curve, config_t *cfg, gen_t generators[],
+ arg_t *argss[], int start_offset, int end_offset) {
+ return exhaustive_gen_retry(curve, cfg, generators, argss, start_offset,
+ end_offset, 0);
+}
+
void exhaustive_quit(arg_t *argss[]) {
equation_quit();
for (size_t i = 0; i < OFFSET_END; ++i) {
@@ -158,8 +178,8 @@ int exhaustive_do(config_t *cfg) {
for (long i = 0; i < cfg->count; ++i) {
curve_t *curve = curve_new();
- if (!exhaustive_gen(curve, cfg, generators, argss, OFFSET_SEED,
- OFFSET_END)) {
+ if (!exhaustive_gen_retry(curve, cfg, generators, argss, OFFSET_SEED,
+ OFFSET_END, 10)) {
curve_free(&curve);
return 1;
}
diff --git a/src/exhaustive/exhaustive.h b/src/exhaustive/exhaustive.h
index ee81874..76e8000 100644
--- a/src/exhaustive/exhaustive.h
+++ b/src/exhaustive/exhaustive.h
@@ -13,6 +13,21 @@
/**
*
* @param curve
+ * @param cfg
+ * @param generators
+ * @param argss
+ * @param start_offset
+ * @param end_offset
+ * @param retry
+ * @return
+ */
+int exhaustive_gen_retry(curve_t *curve, config_t *cfg, gen_t generators[],
+ arg_t *argss[], int start_offset, int end_offset,
+ int retry);
+
+/**
+ *
+ * @param curve
* @param config
* @param generators
* @param argss