2004-12-23 15:16:30 +02:00
|
|
|
#include "cmph_structs.h"
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2005-01-05 22:45:33 +02:00
|
|
|
//#define DEBUG
|
2004-12-23 15:16:30 +02:00
|
|
|
#include "debug.h"
|
|
|
|
|
2005-01-24 22:25:58 +02:00
|
|
|
cmph_config_t *__config_new(cmph_io_adapter_t *key_source)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
2005-01-21 22:42:33 +02:00
|
|
|
cmph_config_t *mph = (cmph_config_t *)malloc(sizeof(cmph_config_t));
|
2004-12-23 15:16:30 +02:00
|
|
|
if (mph == NULL) return NULL;
|
2011-03-27 11:41:28 +03:00
|
|
|
memset(mph, 0, sizeof(cmph_config_t));
|
2004-12-23 15:16:30 +02:00
|
|
|
mph->key_source = key_source;
|
|
|
|
mph->verbosity = 0;
|
2005-01-27 15:01:45 +02:00
|
|
|
mph->data = NULL;
|
2005-09-02 20:51:17 +03:00
|
|
|
mph->c = 0;
|
2004-12-23 15:16:30 +02:00
|
|
|
return mph;
|
|
|
|
}
|
|
|
|
|
2005-01-21 22:42:33 +02:00
|
|
|
void __config_destroy(cmph_config_t *mph)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
|
|
|
free(mph);
|
|
|
|
}
|
|
|
|
|
2005-01-21 22:42:33 +02:00
|
|
|
void __cmph_dump(cmph_t *mphf, FILE *fd)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
2009-06-12 08:46:18 +03:00
|
|
|
register size_t nbytes;
|
2009-03-15 01:24:05 +02:00
|
|
|
nbytes = fwrite(cmph_names[mphf->algo], (size_t)(strlen(cmph_names[mphf->algo]) + 1), (size_t)1, fd);
|
|
|
|
nbytes = fwrite(&(mphf->size), sizeof(mphf->size), (size_t)1, fd);
|
2004-12-23 15:16:30 +02:00
|
|
|
}
|
2011-12-26 23:35:30 +02:00
|
|
|
cmph_t *__cmph_load(FILE *f)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
2005-01-21 22:42:33 +02:00
|
|
|
cmph_t *mphf = NULL;
|
2005-01-18 23:06:08 +02:00
|
|
|
cmph_uint32 i;
|
2004-12-23 15:16:30 +02:00
|
|
|
char algo_name[BUFSIZ];
|
|
|
|
char *ptr = algo_name;
|
2005-01-18 23:06:08 +02:00
|
|
|
CMPH_ALGO algo = CMPH_COUNT;
|
2009-06-12 08:46:18 +03:00
|
|
|
register size_t nbytes;
|
2011-12-26 23:35:30 +02:00
|
|
|
|
2004-12-23 15:16:30 +02:00
|
|
|
DEBUGP("Loading mphf\n");
|
|
|
|
while(1)
|
|
|
|
{
|
2009-06-12 08:46:18 +03:00
|
|
|
size_t c = fread(ptr, (size_t)1, (size_t)1, f);
|
2004-12-23 15:16:30 +02:00
|
|
|
if (c != 1) return NULL;
|
|
|
|
if (*ptr == 0) break;
|
|
|
|
++ptr;
|
|
|
|
}
|
2005-01-18 23:06:08 +02:00
|
|
|
for(i = 0; i < CMPH_COUNT; ++i)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
2005-01-18 23:06:08 +02:00
|
|
|
if (strcmp(algo_name, cmph_names[i]) == 0)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
|
|
|
algo = i;
|
|
|
|
}
|
|
|
|
}
|
2011-12-26 23:35:30 +02:00
|
|
|
if (algo == CMPH_COUNT)
|
2004-12-23 15:16:30 +02:00
|
|
|
{
|
|
|
|
DEBUGP("Algorithm %s not found\n", algo_name);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-01-21 22:42:33 +02:00
|
|
|
mphf = (cmph_t *)malloc(sizeof(cmph_t));
|
2004-12-23 15:16:30 +02:00
|
|
|
mphf->algo = algo;
|
2009-03-15 01:24:05 +02:00
|
|
|
nbytes = fread(&(mphf->size), sizeof(mphf->size), (size_t)1, f);
|
2004-12-23 15:16:30 +02:00
|
|
|
mphf->data = NULL;
|
2005-01-18 23:06:08 +02:00
|
|
|
DEBUGP("Algorithm is %s and mphf is sized %u\n", cmph_names[algo], mphf->size);
|
2004-12-23 15:16:30 +02:00
|
|
|
|
|
|
|
return mphf;
|
|
|
|
}
|