1
Fork 0
turbonss/src/cmph_structs.c

68 lines
1.3 KiB
C
Raw Normal View History

2004-12-23 15:16:30 +02:00
#include "cmph_structs.h"
#include <string.h>
//#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
{
cmph_config_t *mph = (cmph_config_t *)malloc(sizeof(cmph_config_t));
memset(mph, 0, sizeof(cmph_config_t));
2004-12-23 15:16:30 +02:00
if (mph == NULL) return NULL;
mph->key_source = key_source;
mph->verbosity = 0;
mph->data = NULL;
mph->c = 0;
2004-12-23 15:16:30 +02:00
return mph;
}
void __config_destroy(cmph_config_t *mph)
2004-12-23 15:16:30 +02:00
{
free(mph);
}
void __cmph_dump(cmph_t *mphf, FILE *fd)
2004-12-23 15:16:30 +02:00
{
2005-01-18 23:06:08 +02:00
fwrite(cmph_names[mphf->algo], (cmph_uint32)(strlen(cmph_names[mphf->algo]) + 1), 1, fd);
fwrite(&(mphf->size), sizeof(mphf->size), 1, fd);
2004-12-23 15:16:30 +02:00
}
cmph_t *__cmph_load(FILE *f)
2004-12-23 15:16:30 +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;
2004-12-23 15:16:30 +02:00
DEBUGP("Loading mphf\n");
while(1)
{
2005-01-18 23:06:08 +02:00
cmph_uint32 c = fread(ptr, 1, 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;
}
}
2005-01-18 23:06:08 +02:00
if (algo == CMPH_COUNT)
2004-12-23 15:16:30 +02:00
{
DEBUGP("Algorithm %s not found\n", algo_name);
return NULL;
}
mphf = (cmph_t *)malloc(sizeof(cmph_t));
2004-12-23 15:16:30 +02:00
mphf->algo = algo;
fread(&(mphf->size), sizeof(mphf->size), 1, f);
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;
}