From c5ce704d0e3c5185bb8e8f3e7c13180d7aedf393 Mon Sep 17 00:00:00 2001 From: fc_botelho Date: Thu, 3 Aug 2006 20:00:11 +0000 Subject: [PATCH] FCH algorithm added but not tested... --- src/bmz.c | 4 +-- src/cmph.c | 89 +++++++++++++++++++++--------------------------- src/cmph_types.h | 2 +- src/fch.c | 2 +- src/main.c | 2 +- 5 files changed, 44 insertions(+), 55 deletions(-) diff --git a/src/bmz.c b/src/bmz.c index 0009ce1..e4d1c31 100644 --- a/src/bmz.c +++ b/src/bmz.c @@ -367,7 +367,7 @@ static void bmz_traverse(bmz_config_data_t *bmz, cmph_uint8 * used_edges, cmph_u while((neighbor = graph_next_neighbor(bmz->graph, &it)) != GRAPH_NO_NEIGHBOR) { if(GETBIT(visited,neighbor)) continue; - DEBUGP("Visiting neighbor %u\n", neighbor); + //DEBUGP("Visiting neighbor %u\n", neighbor); *unused_edge_index = next_unused_edge(bmz, used_edges, *unused_edge_index); bmz->g[neighbor] = *unused_edge_index - bmz->g[v]; //if (bmz->g[neighbor] >= bmz->m) bmz->g[neighbor] += bmz->m; @@ -430,7 +430,7 @@ static int bmz_gen_edges(cmph_config_t *mph) mph->key_source->dispose(mph->key_source->data, key, keylen); return 0; } - DEBUGP("Adding edge: %u -> %u for key %s\n", h1, h2, key); + //DEBUGP("Adding edge: %u -> %u for key %s\n", h1, h2, key); mph->key_source->dispose(mph->key_source->data, key, keylen); // fprintf(stderr, "key = %s -- dispose BMZ\n", key); multiple_edges = graph_contains_edge(bmz->graph, h1, h2); diff --git a/src/cmph.c b/src/cmph.c index eb4bf5e..edd3a43 100644 --- a/src/cmph.c +++ b/src/cmph.c @@ -4,6 +4,7 @@ #include "bmz.h" #include "bmz8.h" /* included -- Fabiano */ #include "brz.h" /* included -- Fabiano */ +#include "fch.h" /* included -- Fabiano */ #include #include @@ -11,7 +12,7 @@ //#define DEBUG #include "debug.h" -const char *cmph_names[] = { "bmz", "bmz8", "chm", "brz", NULL }; /* included -- Fabiano */ +const char *cmph_names[] = { "bmz", "bmz8", "chm", "brz", "fch", NULL }; /* included -- Fabiano */ typedef struct { @@ -219,6 +220,9 @@ void cmph_config_set_algo(cmph_config_t *mph, CMPH_ALGO algo) case CMPH_BRZ: brz_config_destroy(mph); break; + case CMPH_FCH: + fch_config_destroy(mph); + break; default: assert(0); } @@ -236,6 +240,9 @@ void cmph_config_set_algo(cmph_config_t *mph, CMPH_ALGO algo) case CMPH_BRZ: mph->data = brz_config_new(); break; + case CMPH_FCH: + mph->data = fch_config_new(); + break; default: assert(0); } @@ -245,76 +252,35 @@ 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) { - switch (mph->algo) + if (mph->algo == CMPH_BRZ) { - case CMPH_CHM: - break; - case CMPH_BMZ: /* included -- Fabiano */ - break; - case CMPH_BMZ8: /* included -- Fabiano */ - break; - case CMPH_BRZ: /* included -- Fabiano */ - brz_config_set_tmp_dir(mph, tmp_dir); - break; - default: - assert(0); + brz_config_set_tmp_dir(mph, tmp_dir); } } void cmph_config_set_mphf_fd(cmph_config_t *mph, FILE *mphf_fd) { - switch (mph->algo) + if (mph->algo == CMPH_BRZ) { - case CMPH_CHM: - break; - case CMPH_BMZ: /* included -- Fabiano */ - break; - case CMPH_BMZ8: /* included -- Fabiano */ - break; - case CMPH_BRZ: /* included -- Fabiano */ - brz_config_set_mphf_fd(mph, mphf_fd); - break; - default: - assert(0); + brz_config_set_mphf_fd(mph, mphf_fd); } } void cmph_config_set_b(cmph_config_t *mph, cmph_uint8 b) { - switch (mph->algo) + if (mph->algo == CMPH_BRZ) { - case CMPH_CHM: - break; - case CMPH_BMZ: /* included -- Fabiano */ - break; - case CMPH_BMZ8: /* included -- Fabiano */ - break; - case CMPH_BRZ: /* included -- Fabiano */ - brz_config_set_b(mph, b); - break; - default: - assert(0); + brz_config_set_b(mph, b); } } void cmph_config_set_memory_availability(cmph_config_t *mph, cmph_uint32 memory_availability) { - switch (mph->algo) + if (mph->algo == CMPH_BRZ) { - 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); + brz_config_set_memory_availability(mph, memory_availability); } - } void cmph_config_destroy(cmph_config_t *mph) @@ -334,6 +300,9 @@ void cmph_config_destroy(cmph_config_t *mph) case CMPH_BRZ: /* included -- Fabiano */ brz_config_destroy(mph); break; + case CMPH_FCH: /* included -- Fabiano */ + fch_config_destroy(mph); + break; default: assert(0); } @@ -361,6 +330,9 @@ void cmph_config_set_hashfuncs(cmph_config_t *mph, CMPH_HASH *hashfuncs) case CMPH_BRZ: /* included -- Fabiano */ brz_config_set_hashfuncs(mph, hashfuncs); break; + case CMPH_FCH: /* included -- Fabiano */ + fch_config_set_hashfuncs(mph, hashfuncs); + break; default: break; } @@ -400,6 +372,11 @@ cmph_t *cmph_new(cmph_config_t *mph) if (c == 0) c = 1.15; mphf = brz_new(mph, c); break; + case CMPH_FCH: /* included -- Fabiano */ + DEBUGP("Creating fch hash\n"); + if (c <= 2) c = 2.1; + mphf = fch_new(mph, c); + break; default: assert(0); } @@ -418,6 +395,8 @@ int cmph_dump(cmph_t *mphf, FILE *f) return bmz8_dump(mphf, f); case CMPH_BRZ: /* included -- Fabiano */ return brz_dump(mphf, f); + case CMPH_FCH: /* included -- Fabiano */ + return fch_dump(mphf, f); default: assert(0); } @@ -449,6 +428,10 @@ cmph_t *cmph_load(FILE *f) DEBUGP("Loading brz algorithm dependent parts\n"); brz_load(f, mphf); break; + case CMPH_FCH: /* included -- Fabiano */ + DEBUGP("Loading fch algorithm dependent parts\n"); + fch_load(f, mphf); + break; default: assert(0); } @@ -473,6 +456,9 @@ cmph_uint32 cmph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen) case CMPH_BRZ: /* included -- Fabiano */ DEBUGP("brz algorithm search\n"); return brz_search(mphf, key, keylen); + case CMPH_FCH: /* included -- Fabiano */ + DEBUGP("fch algorithm search\n"); + return fch_search(mphf, key, keylen); default: assert(0); } @@ -501,6 +487,9 @@ void cmph_destroy(cmph_t *mphf) case CMPH_BRZ: /* included -- Fabiano */ brz_destroy(mphf); return; + case CMPH_FCH: /* included -- Fabiano */ + fch_destroy(mphf); + return; default: assert(0); } diff --git a/src/cmph_types.h b/src/cmph_types.h index be976ee..941059b 100644 --- a/src/cmph_types.h +++ b/src/cmph_types.h @@ -9,7 +9,7 @@ typedef float cmph_float32; typedef enum { CMPH_HASH_DJB2, CMPH_HASH_FNV, CMPH_HASH_JENKINS, CMPH_HASH_SDBM, CMPH_HASH_COUNT } CMPH_HASH; extern const char *cmph_hash_names[]; -typedef enum { CMPH_BMZ, CMPH_BMZ8, CMPH_CHM, CMPH_BRZ, CMPH_COUNT } CMPH_ALGO; /* included -- Fabiano */ +typedef enum { CMPH_BMZ, CMPH_BMZ8, CMPH_CHM, CMPH_BRZ, CMPH_FCH, CMPH_COUNT } CMPH_ALGO; /* included -- Fabiano */ extern const char *cmph_names[]; #endif diff --git a/src/fch.c b/src/fch.c index 0477d27..b4321b9 100644 --- a/src/fch.c +++ b/src/fch.c @@ -12,7 +12,7 @@ #include #include #define INDEX 0 /* alignment index within a bucket */ -//#define DEBUG +#define DEBUG #include "debug.h" static cmph_uint32 mixh10h11h12(cmph_uint32 b, cmph_float32 p1, cmph_float32 p2, cmph_uint32 initial_index); diff --git a/src/main.c b/src/main.c index 07765d9..11459dc 100644 --- a/src/main.c +++ b/src/main.c @@ -61,7 +61,7 @@ int main(int argc, char **argv) cmph_uint32 nhashes = 0; cmph_uint32 i; CMPH_ALGO mph_algo = CMPH_CHM; - float c = 2.09; + float c = 0; cmph_config_t *config = NULL; cmph_t *mphf = NULL; char * tmp_dir = NULL;