diff options
author | Xavier Roche <xroche@users.noreply.github.com> | 2013-07-12 18:03:14 +0000 |
---|---|---|
committer | Xavier Roche <xroche@users.noreply.github.com> | 2013-07-12 18:03:14 +0000 |
commit | 1ed1ddf658370994ece99f904b386256374ab2d1 (patch) | |
tree | a7929cc3d4b139f83dfd3be0eb1bcbed1fcc3046 /src/htscoremain.c | |
parent | 676776e99be7a347eab5d4bbf4196204467571f5 (diff) |
Experiments with MurmurHash3 as hashing function for the hashtable
Diffstat (limited to 'src/htscoremain.c')
-rw-r--r-- | src/htscoremain.c | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/src/htscoremain.c b/src/htscoremain.c index 3af785e..ea89810 100644 --- a/src/htscoremain.c +++ b/src/htscoremain.c @@ -2374,7 +2374,7 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { case '7': // hashtable selftest: httrack -#7 nb_entries if (++na < argc) { char *const snum = strdup(argv[na]); - unsigned long count; + unsigned long count = 0; const char *const names[] = { "", "add", "delete", "dry-add", "dry-del", "test-exists", "test-not-exist" @@ -2419,14 +2419,56 @@ HTSEXT_API int hts_main2(int argc, char **argv, httrackp * opt) { { TEST_ADD, 42, 2 }, /* check 42/2 */ { DO_END } }; + char *buff = NULL; + const char **strings = NULL; + + /* produce key #i */ #define FMT() \ - char name[256]; \ + char buffer[256]; \ + char *name = buffer; \ const long expected = (long) i * 1664525 + 1013904223; \ - snprintf(name, sizeof(name), \ - "http://www.example.com/website/sample/for/hashtable/" \ - "%ld/index.html?foo=%ld&bar", \ - (long) i, (long) (expected)) - if (sscanf(snum, "%lu", &count) == 1) { + do { \ + if (strings == NULL) { \ + snprintf(name, sizeof(name), \ + "http://www.example.com/website/sample/for/hashtable/" \ + "%ld/index.html?foo=%ld&bar", \ + (long) i, (long) (expected)); \ + } else { \ + name = strings[i]; \ + } \ + } while(0) + + /* produce random patterns, or read from a file */ + if (sscanf(snum, "%lu", &count) != 1) { + const off_t size = fsize(snum); + FILE *fp = fopen(snum, "rb"); + if (fp != NULL) { + buff = malloc(size); + if (buff != NULL && fread(buff, 1, size, fp) == size) { + size_t capa = 0; + size_t i, last; + for(i = 0, last = 0, count = 0 ; i < size ; i++) { + if (buff[i] == 10 || buff[i] == 0) { + buff[i] = '\0'; + if (capa == count) { + if (capa == 0) { + capa = 16; + } else { + capa <<= 1; + } + strings = realloc(strings, capa*sizeof(char*)); + } + strings[count++] = &buff[last]; + last = i + 1; + } + } + } + fclose(fp); + } + } + + /* successfully read */ + if (count > 0) { inthash hashtable = inthash_new(0); size_t loop; for(loop = 0 ; bench[loop].type != DO_END ; loop++) { |