1
Fork 0
turbonss/src/cmph.c

178 lines
3.5 KiB
C
Raw Normal View History

2004-12-23 15:16:30 +02:00
#include "cmph.h"
#include "cmph_structs.h"
#include "czech.h"
#include "bmz.h"
//#include "bmz.h" /* included -- Fabiano */
#include <stdlib.h>
#include <assert.h>
//#define DEBUG
#include "debug.h"
2005-01-18 23:06:08 +02:00
const char *cmph_names[] = { "czech", "bmz", NULL }; /* included -- Fabiano */
2004-12-23 15:16:30 +02:00
2005-01-18 23:06:08 +02:00
cmph_mph_t *cmph_mph_new(CMPH_ALGO algo, cmph_key_source_t *key_source)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
cmph_mph_t *mph = NULL;
DEBUGP("Creating mph with algorithm %s\n", cmph_names[algo]);
2004-12-23 15:16:30 +02:00
switch (algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
mph = cmph_czech_mph_new(key_source);
2004-12-23 15:16:30 +02:00
break;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
2004-12-23 15:16:30 +02:00
DEBUGP("new bmz algorithm \n");
2005-01-18 23:06:08 +02:00
mph = cmph_bmz_mph_new(key_source);
2004-12-23 15:16:30 +02:00
break;
default:
assert(0);
}
assert(mph);
return mph;
}
2005-01-18 23:06:08 +02:00
void cmph_mph_destroy(cmph_mph_t *mph)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
DEBUGP("Destroying mph with algo %s\n", cmph_names[mph->algo]);
2004-12-23 15:16:30 +02:00
switch (mph->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
cmph_czech_mph_destroy(mph);
2004-12-23 15:16:30 +02:00
break;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
cmph_bmz_mph_destroy(mph);
2004-12-23 15:16:30 +02:00
break;
default:
assert(0);
}
}
2005-01-18 23:06:08 +02:00
void cmph_mph_set_verbosity(cmph_mph_t *mph, cmph_uint32 verbosity)
2004-12-23 15:16:30 +02:00
{
mph->verbosity = verbosity;
}
2005-01-18 23:06:08 +02:00
void cmph_mph_set_hashfuncs(cmph_mph_t *mph, CMPH_HASH *hashfuncs)
2004-12-23 15:16:30 +02:00
{
switch (mph->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
cmph_czech_mph_set_hashfuncs(mph, hashfuncs);
2004-12-23 15:16:30 +02:00
break;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
cmph_bmz_mph_set_hashfuncs(mph, hashfuncs);
2004-12-23 15:16:30 +02:00
break;
default:
break;
}
return;
}
2005-01-18 23:06:08 +02:00
void cmph_mph_set_graphsize(cmph_mph_t *mph, float c)
{
mph->c = c;
return;
}
2004-12-23 15:16:30 +02:00
2005-01-18 23:06:08 +02:00
cmph_mphf_t *cmph_mph_create(cmph_mph_t *mph)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
cmph_mphf_t *mphf = NULL;
float c = mph->c;
2004-12-23 15:16:30 +02:00
switch (mph->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
2004-12-23 15:16:30 +02:00
DEBUGP("Creating czech hash\n");
if (c == 0) c = 2.09;
2005-01-18 23:06:08 +02:00
mphf = cmph_czech_mph_create(mph, c);
2004-12-23 15:16:30 +02:00
break;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
2004-12-23 15:16:30 +02:00
DEBUGP("Creating bmz hash\n");
if (c == 0) c = 1.15;
2005-01-18 23:06:08 +02:00
mphf = cmph_bmz_mph_create(mph, c);
2004-12-23 15:16:30 +02:00
break;
default:
assert(0);
}
return mphf;
}
2005-01-18 23:06:08 +02:00
int cmph_mphf_dump(cmph_mphf_t *mphf, FILE *f)
2004-12-23 15:16:30 +02:00
{
switch (mphf->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
return cmph_czech_mphf_dump(mphf, f);
2004-12-23 15:16:30 +02:00
break;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
return cmph_bmz_mphf_dump(mphf, f);
2004-12-23 15:16:30 +02:00
break;
default:
assert(0);
}
assert(0);
return 0;
}
2005-01-18 23:06:08 +02:00
cmph_mphf_t *cmph_mphf_load(FILE *f)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
cmph_mphf_t *mphf = NULL;
2004-12-23 15:16:30 +02:00
DEBUGP("Loading mphf generic parts\n");
2005-01-18 23:06:08 +02:00
mphf = cmph__mphf_load(f);
2004-12-23 15:16:30 +02:00
if (mphf == NULL) return NULL;
DEBUGP("Loading mphf algorithm dependent parts\n");
switch (mphf->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
cmph_czech_mphf_load(f, mphf);
2004-12-23 15:16:30 +02:00
break;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
2004-12-23 15:16:30 +02:00
DEBUGP("Loading bmz algorithm dependent parts\n");
2005-01-18 23:06:08 +02:00
cmph_bmz_mphf_load(f, mphf);
2004-12-23 15:16:30 +02:00
break;
default:
assert(0);
}
DEBUGP("Loaded mphf\n");
return mphf;
}
2005-01-18 23:06:08 +02:00
cmph_uint32 cmph_mphf_search(cmph_mphf_t *mphf, const char *key, cmph_uint32 keylen)
2004-12-23 15:16:30 +02:00
{
DEBUGP("mphf algorithm: %u \n", mphf->algo);
switch(mphf->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
return cmph_czech_mphf_search(mphf, key, keylen);
case CMPH_BMZ: /* included -- Fabiano */
2004-12-23 15:16:30 +02:00
DEBUGP("bmz algorithm search\n");
2005-01-18 23:06:08 +02:00
return cmph_bmz_mphf_search(mphf, key, keylen);
2004-12-23 15:16:30 +02:00
default:
assert(0);
}
assert(0);
return 0;
2004-12-23 15:16:30 +02:00
}
2005-01-18 23:06:08 +02:00
cmph_uint32 cmph_mphf_size(cmph_mphf_t *mphf)
2004-12-23 15:16:30 +02:00
{
return mphf->size;
}
2005-01-18 23:06:08 +02:00
void cmph_mphf_destroy(cmph_mphf_t *mphf)
2004-12-23 15:16:30 +02:00
{
switch(mphf->algo)
{
2005-01-18 23:06:08 +02:00
case CMPH_CZECH:
cmph_czech_mphf_destroy(mphf);
2004-12-23 15:16:30 +02:00
return;
2005-01-18 23:06:08 +02:00
case CMPH_BMZ: /* included -- Fabiano */
cmph_bmz_mphf_destroy(mphf);
2004-12-23 15:16:30 +02:00
return;
default:
assert(0);
}
assert(0);
return;
}