summaryrefslogtreecommitdiff
path: root/girepository/cmph/cmph_structs.c
blob: b5634248ffc0737d68493272d3e354e02c566f33 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include "cmph_structs.h"

#include <string.h>

//#define DEBUG
#include "debug.h"

cmph_config_t *__config_new(cmph_io_adapter_t *key_source)
{
	cmph_config_t *mph = (cmph_config_t *)malloc(sizeof(cmph_config_t));
	memset(mph, 0, sizeof(cmph_config_t));
	if (mph == NULL) return NULL;
	mph->key_source = key_source;
	mph->verbosity = 0;
	mph->data = NULL;
	mph->c = 0;
	return mph;
}

void __config_destroy(cmph_config_t *mph)
{
	free(mph);
}

void __cmph_dump(cmph_t *mphf, FILE *fd)
{
	register size_t nbytes;
	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);
}
cmph_t *__cmph_load(FILE *f) 
{
	cmph_t *mphf = NULL;
	cmph_uint32 i;
	char algo_name[BUFSIZ];
	char *ptr = algo_name;
	CMPH_ALGO algo = CMPH_COUNT;
	register size_t nbytes;
	
	DEBUGP("Loading mphf\n");
	while(1)
	{
		size_t c = fread(ptr, (size_t)1, (size_t)1, f);
		if (c != 1) return NULL;
		if (*ptr == 0) break;
		++ptr;
	}
	for(i = 0; i < CMPH_COUNT; ++i)
	{
		if (strcmp(algo_name, cmph_names[i]) == 0)
		{
			algo = i;
		}
	}
	if (algo == CMPH_COUNT) 
	{
		DEBUGP("Algorithm %s not found\n", algo_name);
		return NULL;
	}
	mphf = (cmph_t *)malloc(sizeof(cmph_t));
	mphf->algo = algo;
	nbytes = fread(&(mphf->size), sizeof(mphf->size), (size_t)1, f);
	mphf->data = NULL;
	DEBUGP("Algorithm is %s and mphf is sized %u\n", cmph_names[algo],  mphf->size);

	return mphf;
}