Fixed a lot of warnings. Added visual studio project. Make needed changes to work with windows.
This commit is contained in:
32
src/bmz.c
32
src/bmz.c
@@ -9,12 +9,11 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <netinet/in.h>
|
||||
|
||||
//#define DEBUG
|
||||
#include "debug.h"
|
||||
|
||||
static uint32 UNDEFINED = UINT_MAX;
|
||||
//static uint32 UNDEFINED = UINT_MAX;
|
||||
|
||||
static const char bitmask[8] = { 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 };
|
||||
#define GETBIT(array, i) (array[(i) / 8] & bitmask[(i) % 8])
|
||||
@@ -437,7 +436,7 @@ static int bmz_gen_edges(mph_t *mph)
|
||||
if (h1 == h2) if (++h2 >= bmz->n) h2 = 0;
|
||||
if (h1 == h2)
|
||||
{
|
||||
if (mph->verbosity) fprintf(stderr, "Self loop for key %e\n", e);
|
||||
if (mph->verbosity) fprintf(stderr, "Self loop for key %u\n", e);
|
||||
mph->key_source->dispose(mph->key_source->data, key, keylen);
|
||||
return 0;
|
||||
}
|
||||
@@ -457,7 +456,7 @@ int bmz_mphf_dump(mphf_t *mphf, FILE *fd)
|
||||
uint32 buflen;
|
||||
uint32 nbuflen;
|
||||
uint32 i;
|
||||
uint32 two = htonl(2); //number of hash functions
|
||||
uint32 two = 2; //number of hash functions
|
||||
bmz_mphf_data_t *data = (bmz_mphf_data_t *)mphf->data;
|
||||
uint32 nn, nm;
|
||||
__mphf_dump(mphf, fd);
|
||||
@@ -466,28 +465,20 @@ int bmz_mphf_dump(mphf_t *mphf, FILE *fd)
|
||||
|
||||
hash_state_dump(data->hashes[0], &buf, &buflen);
|
||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||
nbuflen = htonl(buflen);
|
||||
fwrite(&nbuflen, sizeof(uint32), 1, fd);
|
||||
fwrite(&buflen, sizeof(uint32), 1, fd);
|
||||
fwrite(buf, buflen, 1, fd);
|
||||
free(buf);
|
||||
|
||||
hash_state_dump(data->hashes[1], &buf, &buflen);
|
||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||
nbuflen = htonl(buflen);
|
||||
fwrite(&nbuflen, sizeof(uint32), 1, fd);
|
||||
fwrite(&buflen, sizeof(uint32), 1, fd);
|
||||
fwrite(buf, buflen, 1, fd);
|
||||
free(buf);
|
||||
|
||||
nn = htonl(data->n);
|
||||
fwrite(&nn, sizeof(uint32), 1, fd);
|
||||
nm = htonl(data->m);
|
||||
fwrite(&nm, sizeof(uint32), 1, fd);
|
||||
fwrite(&(data->n), sizeof(uint32), 1, fd);
|
||||
fwrite(&(data->m), sizeof(uint32), 1, fd);
|
||||
|
||||
for (i = 0; i < data->n; ++i)
|
||||
{
|
||||
uint32 ng = htonl(data->g[i]);
|
||||
fwrite(&ng, sizeof(uint32), 1, fd);
|
||||
}
|
||||
fwrite(data->g, sizeof(uint32)*(data->n), 1, fd);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "G: ");
|
||||
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
||||
@@ -499,17 +490,14 @@ int bmz_mphf_dump(mphf_t *mphf, FILE *fd)
|
||||
void bmz_mphf_load(FILE *f, mphf_t *mphf)
|
||||
{
|
||||
uint32 nhashes;
|
||||
char fbuf[BUFSIZ];
|
||||
char *buf = NULL;
|
||||
uint32 buflen;
|
||||
uint32 i;
|
||||
hash_state_t *state;
|
||||
bmz_mphf_data_t *bmz = (bmz_mphf_data_t *)malloc(sizeof(bmz_mphf_data_t));
|
||||
|
||||
DEBUGP("Loading bmz mphf\n");
|
||||
mphf->data = bmz;
|
||||
fread(&nhashes, sizeof(uint32), 1, f);
|
||||
nhashes = ntohl(nhashes);
|
||||
bmz->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
||||
bmz->hashes[nhashes] = NULL;
|
||||
DEBUGP("Reading %u hashes\n", nhashes);
|
||||
@@ -517,7 +505,6 @@ void bmz_mphf_load(FILE *f, mphf_t *mphf)
|
||||
{
|
||||
hash_state_t *state = NULL;
|
||||
fread(&buflen, sizeof(uint32), 1, f);
|
||||
buflen = ntohl(buflen);
|
||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||
buf = (char *)malloc(buflen);
|
||||
fread(buf, buflen, 1, f);
|
||||
@@ -528,13 +515,10 @@ void bmz_mphf_load(FILE *f, mphf_t *mphf)
|
||||
|
||||
DEBUGP("Reading m and n\n");
|
||||
fread(&(bmz->n), sizeof(uint32), 1, f);
|
||||
bmz->n = ntohl(bmz->n);
|
||||
fread(&(bmz->m), sizeof(uint32), 1, f);
|
||||
bmz->m = ntohl(bmz->m);
|
||||
|
||||
bmz->g = (uint32 *)malloc(sizeof(uint32)*bmz->n);
|
||||
fread(bmz->g, bmz->n*sizeof(uint32), 1, f);
|
||||
for (i = 0; i < bmz->n; ++i) bmz->g[i] = ntohl(bmz->g[i]);
|
||||
#ifdef DEBUG
|
||||
fprintf(stderr, "G: ");
|
||||
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
|
||||
|
||||
Reference in New Issue
Block a user