From 5786c25e07292aa4b9df65f44c8be532d429767d Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Mon, 17 Jan 2011 14:30:00 +0100 Subject: [PATCH] sn-count-cuts: Implement the "-1" (exit after collision) option. --- src/sn-count-cuts.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/sn-count-cuts.c b/src/sn-count-cuts.c index d6e13f9..f5a810c 100644 --- a/src/sn-count-cuts.c +++ b/src/sn-count-cuts.c @@ -37,6 +37,8 @@ static int cuts_num = 0; static uint64_t iterations_num = 1000000; static char *input_file = NULL; +static _Bool exit_after_collision = 0; + static sn_hashtable_t *hashtable; static double possible_cuts (int inputs_num) /* {{{ */ @@ -63,6 +65,7 @@ static void exit_usage (void) /* {{{ */ printf ("sn-count-cuts [options] \n" "\n" "Options:\n" + " -1 Exit after the first collision has been detected.\n" " -c Number of cuts to perform.\n" " -n Maximum number of cuts to perform.\n" " -h Display this help and exit.\n" @@ -74,10 +77,14 @@ static int read_options (int argc, char **argv) /* {{{ */ { int option; - while ((option = getopt (argc, argv, "c:n:h")) != -1) + while ((option = getopt (argc, argv, "1c:n:h")) != -1) { switch (option) { + case '1': + exit_after_collision = 1; + break; + case 'c': { int tmp = atoi (optarg); @@ -200,6 +207,10 @@ int main (int argc, char **argv) /* {{{ */ { create_random_cut (n); + if (exit_after_collision) + if (sn_hashtable_get_collisions (hashtable) > 0) + break; + if ((i < 100) || ((i < 1000) && (((i + 1) % 10) == 0)) || ((i < 10000) && (((i + 1) % 100) == 0)) -- 2.11.0