From a5b68f040aaeba182a50ea11a52da0d7cb8694ce Mon Sep 17 00:00:00 2001 From: fc_botelho Date: Tue, 6 Sep 2005 14:37:35 +0000 Subject: [PATCH] Stable version of BRZ algorithm with option -M (memory_availability) --- src/brz.c | 2 +- src/brz.h | 1 + src/cmph.c | 19 +++++++++++++++++++ src/cmph.h | 1 + src/main.c | 20 ++++++++++++++++---- 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/src/brz.c b/src/brz.c index 195195d..91df769 100755 --- a/src/brz.c +++ b/src/brz.c @@ -68,7 +68,7 @@ void brz_config_set_hashfuncs(cmph_config_t *mph, CMPH_HASH *hashfuncs) void brz_config_set_memory_availability(cmph_config_t *mph, cmph_uint32 memory_availability) { brz_config_data_t *brz = (brz_config_data_t *)mph->data; - brz->memory_availability = memory_availability*1024*1024; + if(memory_availability > 0) brz->memory_availability = memory_availability*1024*1024; } void brz_config_set_tmp_dir(cmph_config_t *mph, cmph_uint8 *tmp_dir) diff --git a/src/brz.h b/src/brz.h index 886eab2..e1c932e 100644 --- a/src/brz.h +++ b/src/brz.h @@ -9,6 +9,7 @@ typedef struct __brz_config_data_t brz_config_data_t; brz_config_data_t *brz_config_new(); void brz_config_set_hashfuncs(cmph_config_t *mph, CMPH_HASH *hashfuncs); void brz_config_set_tmp_dir(cmph_config_t *mph, cmph_uint8 *tmp_dir); +void brz_config_set_memory_availability(cmph_config_t *mph, cmph_uint32 memory_availability); void brz_config_destroy(cmph_config_t *mph); cmph_t *brz_new(cmph_config_t *mph, float c); diff --git a/src/cmph.c b/src/cmph.c index 30bee18..9f0b464 100644 --- a/src/cmph.c +++ b/src/cmph.c @@ -204,6 +204,25 @@ void cmph_config_set_tmp_dir(cmph_config_t *mph, cmph_uint8 *tmp_dir) } +void cmph_config_set_memory_availability(cmph_config_t *mph, cmph_uint32 memory_availability) +{ + switch (mph->algo) + { + case CMPH_CHM: + break; + case CMPH_BMZ: /* included -- Fabiano */ + break; + case CMPH_BMZ8: /* included -- Fabiano */ + break; + case CMPH_BRZ: /* included -- Fabiano */ + brz_config_set_memory_availability(mph, memory_availability); + break; + default: + assert(0); + } + +} + void cmph_config_destroy(cmph_config_t *mph) { DEBUGP("Destroying mph with algo %s\n", cmph_names[mph->algo]); diff --git a/src/cmph.h b/src/cmph.h index c301a91..88ed317 100644 --- a/src/cmph.h +++ b/src/cmph.h @@ -36,6 +36,7 @@ void cmph_config_set_verbosity(cmph_config_t *mph, cmph_uint32 verbosity); void cmph_config_set_graphsize(cmph_config_t *mph, float c); void cmph_config_set_algo(cmph_config_t *mph, CMPH_ALGO algo); void cmph_config_set_tmp_dir(cmph_config_t *mph, cmph_uint8 *tmp_dir); +void cmph_config_set_memory_availability(cmph_config_t *mph, cmph_uint32 memory_availability); void cmph_config_destroy(cmph_config_t *mph); /** Hash API **/ diff --git a/src/main.c b/src/main.c index 6416359..5694108 100644 --- a/src/main.c +++ b/src/main.c @@ -22,12 +22,12 @@ void usage(const char *prg) { - fprintf(stderr, "usage: %s [-v] [-h] [-V] [-k nkeys] [-f hash_function] [-g [-c value][-s seed] ] [-a algorithm] [-d tmp_dir] [-m file.mph] keysfile\n", prg); + fprintf(stderr, "usage: %s [-v] [-h] [-V] [-k nkeys] [-f hash_function] [-g [-c value][-s seed] ] [-a algorithm] [-M memory_in_MB] [-d tmp_dir] [-m file.mph] keysfile\n", prg); } void usage_long(const char *prg) { cmph_uint32 i; - fprintf(stderr, "usage: %s [-v] [-h] [-V] [-k nkeys] [-f hash_function] [-g [-c value][-s seed] ] [-a algorithm] [-d tmp_dir] [-m file.mph] keysfile\n", prg); + fprintf(stderr, "usage: %s [-v] [-h] [-V] [-k nkeys] [-f hash_function] [-g [-c value][-s seed] ] [-a algorithm] [-M memory_in_MB] [-d tmp_dir] [-m file.mph] keysfile\n", prg); fprintf(stderr, "Minimum perfect hashing tool\n\n"); fprintf(stderr, " -h\t print this help message\n"); fprintf(stderr, " -c\t c value that determines the number of vertices in the graph\n"); @@ -41,6 +41,7 @@ void usage_long(const char *prg) fprintf(stderr, " -g\t generation mode\n"); fprintf(stderr, " -s\t random seed\n"); fprintf(stderr, " -m\t minimum perfect hash function file \n"); + fprintf(stderr, " -M\t main memory availability (in MB)\n"); fprintf(stderr, " -d\t temporary directory used in brz algorithm \n"); fprintf(stderr, " keysfile\t line separated file with keys\n"); } @@ -65,10 +66,10 @@ int main(int argc, char **argv) cmph_t *mphf = NULL; cmph_uint8 * tmp_dir = NULL; cmph_io_adapter_t *source; - + cmph_uint32 memory_availability = 0; while (1) { - char ch = getopt(argc, argv, "hVvgc:k:a:f:m:d:s:"); + char ch = getopt(argc, argv, "hVvgc:k:a:M:f:m:d:s:"); if (ch == -1) break; switch (ch) { @@ -111,6 +112,16 @@ int main(int argc, char **argv) case 'd': tmp_dir = strdup(optarg); break; + case 'M': + { + char *cptr; + memory_availability = strtoul(optarg, &cptr, 10); + if(*cptr != 0) { + fprintf(stderr, "Invalid memory availability %s\n", optarg); + exit(1); + } + } + break; case 'v': ++verbosity; break; @@ -202,6 +213,7 @@ int main(int argc, char **argv) if (nhashes) cmph_config_set_hashfuncs(config, hashes); cmph_config_set_verbosity(config, verbosity); cmph_config_set_tmp_dir(config, tmp_dir); + cmph_config_set_memory_availability(config, memory_availability); if(mph_algo == CMPH_BMZ && c >= 2.0) c=1.15; if (c != 0) cmph_config_set_graphsize(config, c); mphf = cmph_new(config);