Fixed a lot of warnings. Added visual studio project. Make needed changes to work with windows.
This commit is contained in:
parent
eea53e77f0
commit
d24b968de4
4
COPYING
4
COPYING
@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least
|
|||||||
the "copyright" line and a pointer to where the full notice is found.
|
the "copyright" line and a pointer to where the full notice is found.
|
||||||
|
|
||||||
<one line to give the program's name and a brief idea of what it does.>
|
<one line to give the program's name and a brief idea of what it does.>
|
||||||
Copyright (C) <year> <name of author>
|
Copyright (C) 19yy <name of author>
|
||||||
|
|
||||||
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
||||||
@ -313,7 +313,7 @@ Also add information on how to contact you by electronic and paper mail.
|
|||||||
If the program is interactive, make it output a short notice like this
|
If the program is interactive, make it output a short notice like this
|
||||||
when it starts in an interactive mode:
|
when it starts in an interactive mode:
|
||||||
|
|
||||||
Gnomovision version 69, Copyright (C) year name of author
|
Gnomovision version 69, Copyright (C) 19yy name of author
|
||||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||||
This is free software, and you are welcome to redistribute it
|
This is free software, and you are welcome to redistribute it
|
||||||
under certain conditions; type `show c' for details.
|
under certain conditions; type `show c' for details.
|
||||||
|
@ -18,5 +18,5 @@ libcmph_la_SOURCES = debug.h\
|
|||||||
|
|
||||||
libcmph_la_LDFLAGS = -version-info 0:0:0
|
libcmph_la_LDFLAGS = -version-info 0:0:0
|
||||||
|
|
||||||
cmph_SOURCES = main.c
|
cmph_SOURCES = main.c ../wingetopt.h ../wingetopt.c
|
||||||
cmph_LDADD = libcmph.la
|
cmph_LDADD = libcmph.la
|
||||||
|
32
src/bmz.c
32
src/bmz.c
@ -9,12 +9,11 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
#include "debug.h"
|
#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 };
|
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])
|
#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 (++h2 >= bmz->n) h2 = 0;
|
||||||
if (h1 == h2)
|
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);
|
mph->key_source->dispose(mph->key_source->data, key, keylen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -457,7 +456,7 @@ int bmz_mphf_dump(mphf_t *mphf, FILE *fd)
|
|||||||
uint32 buflen;
|
uint32 buflen;
|
||||||
uint32 nbuflen;
|
uint32 nbuflen;
|
||||||
uint32 i;
|
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;
|
bmz_mphf_data_t *data = (bmz_mphf_data_t *)mphf->data;
|
||||||
uint32 nn, nm;
|
uint32 nn, nm;
|
||||||
__mphf_dump(mphf, fd);
|
__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);
|
hash_state_dump(data->hashes[0], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
nbuflen = htonl(buflen);
|
fwrite(&buflen, sizeof(uint32), 1, fd);
|
||||||
fwrite(&nbuflen, sizeof(uint32), 1, fd);
|
|
||||||
fwrite(buf, buflen, 1, fd);
|
fwrite(buf, buflen, 1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[1], &buf, &buflen);
|
hash_state_dump(data->hashes[1], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
nbuflen = htonl(buflen);
|
fwrite(&buflen, sizeof(uint32), 1, fd);
|
||||||
fwrite(&nbuflen, sizeof(uint32), 1, fd);
|
|
||||||
fwrite(buf, buflen, 1, fd);
|
fwrite(buf, buflen, 1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
nn = htonl(data->n);
|
fwrite(&(data->n), sizeof(uint32), 1, fd);
|
||||||
fwrite(&nn, sizeof(uint32), 1, fd);
|
fwrite(&(data->m), sizeof(uint32), 1, fd);
|
||||||
nm = htonl(data->m);
|
|
||||||
fwrite(&nm, sizeof(uint32), 1, fd);
|
|
||||||
|
|
||||||
for (i = 0; i < data->n; ++i)
|
fwrite(data->g, sizeof(uint32)*(data->n), 1, fd);
|
||||||
{
|
|
||||||
uint32 ng = htonl(data->g[i]);
|
|
||||||
fwrite(&ng, sizeof(uint32), 1, fd);
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
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)
|
void bmz_mphf_load(FILE *f, mphf_t *mphf)
|
||||||
{
|
{
|
||||||
uint32 nhashes;
|
uint32 nhashes;
|
||||||
char fbuf[BUFSIZ];
|
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
uint32 buflen;
|
uint32 buflen;
|
||||||
uint32 i;
|
uint32 i;
|
||||||
hash_state_t *state;
|
|
||||||
bmz_mphf_data_t *bmz = (bmz_mphf_data_t *)malloc(sizeof(bmz_mphf_data_t));
|
bmz_mphf_data_t *bmz = (bmz_mphf_data_t *)malloc(sizeof(bmz_mphf_data_t));
|
||||||
|
|
||||||
DEBUGP("Loading bmz mphf\n");
|
DEBUGP("Loading bmz mphf\n");
|
||||||
mphf->data = bmz;
|
mphf->data = bmz;
|
||||||
fread(&nhashes, sizeof(uint32), 1, f);
|
fread(&nhashes, sizeof(uint32), 1, f);
|
||||||
nhashes = ntohl(nhashes);
|
|
||||||
bmz->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
bmz->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
||||||
bmz->hashes[nhashes] = NULL;
|
bmz->hashes[nhashes] = NULL;
|
||||||
DEBUGP("Reading %u hashes\n", nhashes);
|
DEBUGP("Reading %u hashes\n", nhashes);
|
||||||
@ -517,7 +505,6 @@ void bmz_mphf_load(FILE *f, mphf_t *mphf)
|
|||||||
{
|
{
|
||||||
hash_state_t *state = NULL;
|
hash_state_t *state = NULL;
|
||||||
fread(&buflen, sizeof(uint32), 1, f);
|
fread(&buflen, sizeof(uint32), 1, f);
|
||||||
buflen = ntohl(buflen);
|
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc(buflen);
|
buf = (char *)malloc(buflen);
|
||||||
fread(buf, buflen, 1, f);
|
fread(buf, buflen, 1, f);
|
||||||
@ -528,13 +515,10 @@ void bmz_mphf_load(FILE *f, mphf_t *mphf)
|
|||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(bmz->n), sizeof(uint32), 1, f);
|
fread(&(bmz->n), sizeof(uint32), 1, f);
|
||||||
bmz->n = ntohl(bmz->n);
|
|
||||||
fread(&(bmz->m), sizeof(uint32), 1, f);
|
fread(&(bmz->m), sizeof(uint32), 1, f);
|
||||||
bmz->m = ntohl(bmz->m);
|
|
||||||
|
|
||||||
bmz->g = (uint32 *)malloc(sizeof(uint32)*bmz->n);
|
bmz->g = (uint32 *)malloc(sizeof(uint32)*bmz->n);
|
||||||
fread(bmz->g, bmz->n*sizeof(uint32), 1, f);
|
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
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
|
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
|
||||||
|
@ -14,5 +14,6 @@ mphf_t *bmz_mph_create(mph_t *mph, float bmz_c);
|
|||||||
|
|
||||||
void bmz_mphf_load(FILE *f, mphf_t *mphf);
|
void bmz_mphf_load(FILE *f, mphf_t *mphf);
|
||||||
int bmz_mphf_dump(mphf_t *mphf, FILE *f);
|
int bmz_mphf_dump(mphf_t *mphf, FILE *f);
|
||||||
|
void bmz_mphf_destroy(mphf_t *mphf);
|
||||||
uint32 bmz_mphf_search(mphf_t *mphf, const char *key, uint32 keylen);
|
uint32 bmz_mphf_search(mphf_t *mphf, const char *key, uint32 keylen);
|
||||||
#endif
|
#endif
|
||||||
|
12
src/cmph.c
12
src/cmph.c
@ -68,18 +68,26 @@ void mph_set_hashfuncs(mph_t *mph, CMPH_HASH *hashfuncs)
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
void mph_set_graphsize(mph_t *mph, float c)
|
||||||
|
{
|
||||||
|
mph->c = c;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
mphf_t *mph_create(mph_t *mph, float c)
|
mphf_t *mph_create(mph_t *mph)
|
||||||
{
|
{
|
||||||
mphf_t *mphf = NULL;
|
mphf_t *mphf = NULL;
|
||||||
|
float c = mph->c;
|
||||||
switch (mph->algo)
|
switch (mph->algo)
|
||||||
{
|
{
|
||||||
case MPH_CZECH:
|
case MPH_CZECH:
|
||||||
DEBUGP("Creating czech hash\n");
|
DEBUGP("Creating czech hash\n");
|
||||||
|
if (c == 0) c = 2.09;
|
||||||
mphf = czech_mph_create(mph, c);
|
mphf = czech_mph_create(mph, c);
|
||||||
break;
|
break;
|
||||||
case MPH_BMZ: /* included -- Fabiano */
|
case MPH_BMZ: /* included -- Fabiano */
|
||||||
DEBUGP("Creating bmz hash\n");
|
DEBUGP("Creating bmz hash\n");
|
||||||
|
if (c == 0) c = 1.15;
|
||||||
mphf = bmz_mph_create(mph, c);
|
mphf = bmz_mph_create(mph, c);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -143,7 +151,7 @@ uint32 mphf_search(mphf_t *mphf, const char *key, uint32 keylen)
|
|||||||
assert(0);
|
assert(0);
|
||||||
}
|
}
|
||||||
assert(0);
|
assert(0);
|
||||||
return;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32 mphf_size(mphf_t *mphf)
|
uint32 mphf_size(mphf_t *mphf)
|
||||||
|
@ -27,8 +27,9 @@ typedef struct
|
|||||||
mph_t *mph_new(MPH_ALGO algo, key_source_t *key_source);
|
mph_t *mph_new(MPH_ALGO algo, key_source_t *key_source);
|
||||||
void mph_set_hashfuncs(mph_t *mph, CMPH_HASH *hashfuncs);
|
void mph_set_hashfuncs(mph_t *mph, CMPH_HASH *hashfuncs);
|
||||||
void mph_set_verbosity(mph_t *mph, uint32 verbosity);
|
void mph_set_verbosity(mph_t *mph, uint32 verbosity);
|
||||||
|
void mph_set_graphsize(mph_t *mph, float c);
|
||||||
void mph_destroy(mph_t *mph);
|
void mph_destroy(mph_t *mph);
|
||||||
mphf_t *mph_create(mph_t *mph, float c);
|
mphf_t *mph_create(mph_t *mph);
|
||||||
|
|
||||||
/** Hash querying API **/
|
/** Hash querying API **/
|
||||||
mphf_t *mphf_load(FILE *f);
|
mphf_t *mphf_load(FILE *f);
|
||||||
|
@ -13,6 +13,7 @@ mph_t *__mph_new(MPH_ALGO algo, key_source_t *key_source)
|
|||||||
mph->algo = algo;
|
mph->algo = algo;
|
||||||
mph->key_source = key_source;
|
mph->key_source = key_source;
|
||||||
mph->verbosity = 0;
|
mph->verbosity = 0;
|
||||||
|
float c = 0;
|
||||||
return mph;
|
return mph;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ void __mph_destroy(mph_t *mph)
|
|||||||
void __mphf_dump(mphf_t *mphf, FILE *fd)
|
void __mphf_dump(mphf_t *mphf, FILE *fd)
|
||||||
{
|
{
|
||||||
uint32 nsize = htonl(mphf->size);
|
uint32 nsize = htonl(mphf->size);
|
||||||
fwrite(mph_names[mphf->algo], strlen(mph_names[mphf->algo]) + 1, 1, fd);
|
fwrite(mph_names[mphf->algo], (uint32)(strlen(mph_names[mphf->algo]) + 1), 1, fd);
|
||||||
fwrite(&nsize, sizeof(mphf->size), 1, fd);
|
fwrite(&nsize, sizeof(mphf->size), 1, fd);
|
||||||
}
|
}
|
||||||
mphf_t *__mphf_load(FILE *f)
|
mphf_t *__mphf_load(FILE *f)
|
||||||
|
@ -10,6 +10,7 @@ struct __mph_t
|
|||||||
MPH_ALGO algo;
|
MPH_ALGO algo;
|
||||||
key_source_t *key_source;
|
key_source_t *key_source;
|
||||||
uint32 verbosity;
|
uint32 verbosity;
|
||||||
|
float c;
|
||||||
void *data; //algorithm dependent data
|
void *data; //algorithm dependent data
|
||||||
};
|
};
|
||||||
|
|
||||||
|
36
src/czech.c
36
src/czech.c
@ -8,7 +8,6 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -68,7 +67,7 @@ mphf_t *czech_mph_create(mph_t *mph, float c)
|
|||||||
char *visited = NULL;
|
char *visited = NULL;
|
||||||
czech_mph_data_t *czech = (czech_mph_data_t *)mph->data;
|
czech_mph_data_t *czech = (czech_mph_data_t *)mph->data;
|
||||||
czech->m = mph->key_source->nkeys;
|
czech->m = mph->key_source->nkeys;
|
||||||
czech->n = ceil(c * mph->key_source->nkeys);
|
czech->n = (uint32)ceil(c * mph->key_source->nkeys);
|
||||||
DEBUGP("m (edges): %u n (vertices): %u c: %f\n", czech->m, czech->n, c);
|
DEBUGP("m (edges): %u n (vertices): %u c: %f\n", czech->m, czech->n, c);
|
||||||
czech->graph = graph_new(czech->n, czech->m);
|
czech->graph = graph_new(czech->n, czech->m);
|
||||||
DEBUGP("Created graph\n");
|
DEBUGP("Created graph\n");
|
||||||
@ -197,7 +196,7 @@ static int czech_gen_edges(mph_t *mph)
|
|||||||
if (h1 == h2) if (++h2 >= czech->n) h2 = 0;
|
if (h1 == h2) if (++h2 >= czech->n) h2 = 0;
|
||||||
if (h1 == h2)
|
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);
|
mph->key_source->dispose(mph->key_source->data, key, keylen);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -216,39 +215,29 @@ int czech_mphf_dump(mphf_t *mphf, FILE *fd)
|
|||||||
{
|
{
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
uint32 buflen;
|
uint32 buflen;
|
||||||
uint32 nbuflen;
|
uint32 two = 2; //number of hash functions
|
||||||
uint32 i;
|
|
||||||
uint32 two = htonl(2); //number of hash functions
|
|
||||||
czech_mphf_data_t *data = (czech_mphf_data_t *)mphf->data;
|
czech_mphf_data_t *data = (czech_mphf_data_t *)mphf->data;
|
||||||
uint32 nn, nm;
|
|
||||||
__mphf_dump(mphf, fd);
|
__mphf_dump(mphf, fd);
|
||||||
|
|
||||||
fwrite(&two, sizeof(uint32), 1, fd);
|
fwrite(&two, sizeof(uint32), 1, fd);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[0], &buf, &buflen);
|
hash_state_dump(data->hashes[0], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
nbuflen = htonl(buflen);
|
fwrite(&buflen, sizeof(uint32), 1, fd);
|
||||||
fwrite(&nbuflen, sizeof(uint32), 1, fd);
|
|
||||||
fwrite(buf, buflen, 1, fd);
|
fwrite(buf, buflen, 1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
hash_state_dump(data->hashes[1], &buf, &buflen);
|
hash_state_dump(data->hashes[1], &buf, &buflen);
|
||||||
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
DEBUGP("Dumping hash state with %u bytes to disk\n", buflen);
|
||||||
nbuflen = htonl(buflen);
|
fwrite(&buflen, sizeof(uint32), 1, fd);
|
||||||
fwrite(&nbuflen, sizeof(uint32), 1, fd);
|
|
||||||
fwrite(buf, buflen, 1, fd);
|
fwrite(buf, buflen, 1, fd);
|
||||||
free(buf);
|
free(buf);
|
||||||
|
|
||||||
nn = htonl(data->n);
|
fwrite(&(data->n), sizeof(uint32), 1, fd);
|
||||||
fwrite(&nn, sizeof(uint32), 1, fd);
|
fwrite(&(data->m), sizeof(uint32), 1, fd);
|
||||||
nm = htonl(data->m);
|
|
||||||
fwrite(&nm, sizeof(uint32), 1, fd);
|
fwrite(data->g, sizeof(uint32)*data->n, 1, fd);
|
||||||
|
|
||||||
for (i = 0; i < data->n; ++i)
|
|
||||||
{
|
|
||||||
uint32 ng = htonl(data->g[i]);
|
|
||||||
fwrite(&ng, sizeof(uint32), 1, fd);
|
|
||||||
}
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
|
||||||
@ -260,17 +249,14 @@ int czech_mphf_dump(mphf_t *mphf, FILE *fd)
|
|||||||
void czech_mphf_load(FILE *f, mphf_t *mphf)
|
void czech_mphf_load(FILE *f, mphf_t *mphf)
|
||||||
{
|
{
|
||||||
uint32 nhashes;
|
uint32 nhashes;
|
||||||
char fbuf[BUFSIZ];
|
|
||||||
char *buf = NULL;
|
char *buf = NULL;
|
||||||
uint32 buflen;
|
uint32 buflen;
|
||||||
uint32 i;
|
uint32 i;
|
||||||
hash_state_t *state;
|
|
||||||
czech_mphf_data_t *czech = (czech_mphf_data_t *)malloc(sizeof(czech_mphf_data_t));
|
czech_mphf_data_t *czech = (czech_mphf_data_t *)malloc(sizeof(czech_mphf_data_t));
|
||||||
|
|
||||||
DEBUGP("Loading czech mphf\n");
|
DEBUGP("Loading czech mphf\n");
|
||||||
mphf->data = czech;
|
mphf->data = czech;
|
||||||
fread(&nhashes, sizeof(uint32), 1, f);
|
fread(&nhashes, sizeof(uint32), 1, f);
|
||||||
nhashes = ntohl(nhashes);
|
|
||||||
czech->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
czech->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
|
||||||
czech->hashes[nhashes] = NULL;
|
czech->hashes[nhashes] = NULL;
|
||||||
DEBUGP("Reading %u hashes\n", nhashes);
|
DEBUGP("Reading %u hashes\n", nhashes);
|
||||||
@ -278,7 +264,6 @@ void czech_mphf_load(FILE *f, mphf_t *mphf)
|
|||||||
{
|
{
|
||||||
hash_state_t *state = NULL;
|
hash_state_t *state = NULL;
|
||||||
fread(&buflen, sizeof(uint32), 1, f);
|
fread(&buflen, sizeof(uint32), 1, f);
|
||||||
buflen = ntohl(buflen);
|
|
||||||
DEBUGP("Hash state has %u bytes\n", buflen);
|
DEBUGP("Hash state has %u bytes\n", buflen);
|
||||||
buf = (char *)malloc(buflen);
|
buf = (char *)malloc(buflen);
|
||||||
fread(buf, buflen, 1, f);
|
fread(buf, buflen, 1, f);
|
||||||
@ -289,13 +274,10 @@ void czech_mphf_load(FILE *f, mphf_t *mphf)
|
|||||||
|
|
||||||
DEBUGP("Reading m and n\n");
|
DEBUGP("Reading m and n\n");
|
||||||
fread(&(czech->n), sizeof(uint32), 1, f);
|
fread(&(czech->n), sizeof(uint32), 1, f);
|
||||||
czech->n = ntohl(czech->n);
|
|
||||||
fread(&(czech->m), sizeof(uint32), 1, f);
|
fread(&(czech->m), sizeof(uint32), 1, f);
|
||||||
czech->m = ntohl(czech->m);
|
|
||||||
|
|
||||||
czech->g = (uint32 *)malloc(sizeof(uint32)*czech->n);
|
czech->g = (uint32 *)malloc(sizeof(uint32)*czech->n);
|
||||||
fread(czech->g, czech->n*sizeof(uint32), 1, f);
|
fread(czech->g, czech->n*sizeof(uint32), 1, f);
|
||||||
for (i = 0; i < czech->n; ++i) czech->g[i] = ntohl(czech->g[i]);
|
|
||||||
/*
|
/*
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
fprintf(stderr, "G: ");
|
fprintf(stderr, "G: ");
|
||||||
|
@ -14,5 +14,6 @@ mphf_t *czech_mph_create(mph_t *mph, float c);
|
|||||||
|
|
||||||
void czech_mphf_load(FILE *f, mphf_t *mphf);
|
void czech_mphf_load(FILE *f, mphf_t *mphf);
|
||||||
int czech_mphf_dump(mphf_t *mphf, FILE *f);
|
int czech_mphf_dump(mphf_t *mphf, FILE *f);
|
||||||
|
void czech_mphf_destroy(mphf_t *mphf);
|
||||||
uint32 czech_mphf_search(mphf_t *mphf, const char *key, uint32 keylen);
|
uint32 czech_mphf_search(mphf_t *mphf, const char *key, uint32 keylen);
|
||||||
#endif
|
#endif
|
||||||
|
44
src/debug.h
44
src/debug.h
@ -1,15 +1,53 @@
|
|||||||
#ifndef __MY_DEBUGC__
|
#ifdef DEBUGP
|
||||||
#define __MY_DEBUGC__
|
#undef DEBUGP
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <cstring>
|
||||||
|
#endif
|
||||||
#else
|
#else
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#ifdef WIN32
|
||||||
|
#include <string.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#ifndef __DEBUG_H__
|
||||||
|
#define __DEBUG_H__
|
||||||
|
#include <stdarg.h>
|
||||||
|
static void debugprintf(const char *format, ...)
|
||||||
|
{
|
||||||
|
va_list ap;
|
||||||
|
char *f = NULL;
|
||||||
|
const char *p="%s:%d ";
|
||||||
|
size_t plen = strlen(p);
|
||||||
|
va_start(ap, format);
|
||||||
|
f = (char *)malloc(plen + strlen(format) + 1);
|
||||||
|
if (!f) return;
|
||||||
|
memcpy(f, p, plen);
|
||||||
|
memcpy(f + plen, format, strlen(format) + 1);
|
||||||
|
vfprintf(stderr, f, ap);
|
||||||
|
va_end(ap);
|
||||||
|
free(f);
|
||||||
|
}
|
||||||
|
static void dummyprintf(const char *format, ...)
|
||||||
|
{}
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DEBUGP debugprintf
|
||||||
|
#else
|
||||||
#define DEBUGP(args...) do { fprintf(stderr, "%s:%d ", __FILE__, __LINE__); fprintf(stderr, ## args); } while(0)
|
#define DEBUGP(args...) do { fprintf(stderr, "%s:%d ", __FILE__, __LINE__); fprintf(stderr, ## args); } while(0)
|
||||||
|
#endif
|
||||||
|
#else
|
||||||
|
#ifdef WIN32
|
||||||
|
#define DEBUGP dummyprintf
|
||||||
#else
|
#else
|
||||||
#define DEBUGP(args...)
|
#define DEBUGP(args...)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -15,9 +15,9 @@ void djb2_state_destroy(djb2_state_t *state)
|
|||||||
|
|
||||||
uint32 djb2_hash(djb2_state_t *state, const char *k, uint32 keylen)
|
uint32 djb2_hash(djb2_state_t *state, const char *k, uint32 keylen)
|
||||||
{
|
{
|
||||||
register unsigned int hash = 5381;
|
register uint32 hash = 5381;
|
||||||
const unsigned char *ptr = k;
|
const unsigned char *ptr = k;
|
||||||
int i = 0;
|
uint32 i = 0;
|
||||||
while (i < keylen)
|
while (i < keylen)
|
||||||
{
|
{
|
||||||
hash = hash*33 ^ *ptr;
|
hash = hash*33 ^ *ptr;
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
static uint8 bitmask[8] = { 1, 1 << 1, 1 << 2, 1 << 3, 1 << 4, 1 << 5, 1 << 6, 1 << 7 };
|
static const uint8 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])
|
#define GETBIT(array, i) (array[(i) / 8] & bitmask[(i) % 8])
|
||||||
#define SETBIT(array, i) (array[(i) / 8] |= bitmask[(i) % 8])
|
#define SETBIT(array, i) (array[(i) / 8] |= bitmask[(i) % 8])
|
||||||
#define UNSETBIT(array, i) (array[(i) / 8] &= (~(bitmask[(i) % 8])))
|
#define UNSETBIT(array, i) (array[(i) / 8] &= (~(bitmask[(i) % 8])))
|
||||||
|
@ -20,9 +20,10 @@ graph_t *graph_new(uint32 nnodes, uint32 nedges);
|
|||||||
void graph_destroy(graph_t *graph);
|
void graph_destroy(graph_t *graph);
|
||||||
|
|
||||||
void graph_add_edge(graph_t *g, uint32 v1, uint32 v2);
|
void graph_add_edge(graph_t *g, uint32 v1, uint32 v2);
|
||||||
//void graph_del_edge(graph_t *g, uint32 v1, uint32 v2);
|
void graph_del_edge(graph_t *g, uint32 v1, uint32 v2);
|
||||||
void graph_clear_edges(graph_t *g);
|
void graph_clear_edges(graph_t *g);
|
||||||
uint32 graph_edge_id(graph_t *g, uint32 v1, uint32 v2);
|
uint32 graph_edge_id(graph_t *g, uint32 v1, uint32 v2);
|
||||||
|
uint8 graph_contains_edge(graph_t *g, uint32 v1, uint32 v2);
|
||||||
|
|
||||||
graph_iterator_t graph_neighbors_it(graph_t *g, uint32 v);
|
graph_iterator_t graph_neighbors_it(graph_t *g, uint32 v);
|
||||||
uint32 graph_next_neighbor(graph_t *g, graph_iterator_t* it);
|
uint32 graph_next_neighbor(graph_t *g, graph_iterator_t* it);
|
||||||
|
@ -81,7 +81,7 @@ void hash_state_dump(hash_state_t *state, char **buf, uint32 *buflen)
|
|||||||
memcpy(*buf, hash_names[state->hashfunc], strlen(hash_names[state->hashfunc]) + 1);
|
memcpy(*buf, hash_names[state->hashfunc], strlen(hash_names[state->hashfunc]) + 1);
|
||||||
DEBUGP("Algobuf is %u\n", *(uint32 *)algobuf);
|
DEBUGP("Algobuf is %u\n", *(uint32 *)algobuf);
|
||||||
memcpy(*buf + strlen(hash_names[state->hashfunc]) + 1, algobuf, *buflen);
|
memcpy(*buf + strlen(hash_names[state->hashfunc]) + 1, algobuf, *buflen);
|
||||||
*buflen = strlen(hash_names[state->hashfunc]) + 1 + *buflen;
|
*buflen = (uint32)strlen(hash_names[state->hashfunc]) + 1 + *buflen;
|
||||||
free(algobuf);
|
free(algobuf);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -100,7 +100,7 @@ hash_state_t *hash_state_load(const char *buf, uint32 buflen)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (hashfunc == HASH_COUNT) return NULL;
|
if (hashfunc == HASH_COUNT) return NULL;
|
||||||
offset = strlen(hash_names[hashfunc]) + 1;
|
offset = (uint32)strlen(hash_names[hashfunc]) + 1;
|
||||||
switch (hashfunc)
|
switch (hashfunc)
|
||||||
{
|
{
|
||||||
case HASH_JENKINS:
|
case HASH_JENKINS:
|
||||||
|
@ -1,9 +1,11 @@
|
|||||||
#include "jenkins_hash.h"
|
#include "jenkins_hash.h"
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
#ifdef WIN32
|
||||||
|
#define _USE_MATH_DEFINES //For M_LOG2E
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <netinet/in.h>
|
|
||||||
|
|
||||||
//#define DEBUG
|
//#define DEBUG
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
@ -87,7 +89,7 @@ jenkins_state_t *jenkins_state_new(uint32 size) //size of hash table
|
|||||||
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
||||||
DEBUGP("Initializing jenkins hash\n");
|
DEBUGP("Initializing jenkins hash\n");
|
||||||
state->seed = rand() % size;
|
state->seed = rand() % size;
|
||||||
state->nbits = ceil(log(size)/M_LOG2E);
|
state->nbits = (uint32)ceil(log(size)/M_LOG2E);
|
||||||
state->size = size;
|
state->size = size;
|
||||||
DEBUGP("Initialized jenkins with size %u, nbits %u and seed %u\n", size, state->nbits, state->seed);
|
DEBUGP("Initialized jenkins with size %u, nbits %u and seed %u\n", size, state->nbits, state->seed);
|
||||||
return state;
|
return state;
|
||||||
@ -162,9 +164,6 @@ uint32 jenkins_hash(jenkins_state_t *state, const char *k, uint32 keylen)
|
|||||||
|
|
||||||
void jenkins_state_dump(jenkins_state_t *state, char **buf, uint32 *buflen)
|
void jenkins_state_dump(jenkins_state_t *state, char **buf, uint32 *buflen)
|
||||||
{
|
{
|
||||||
uint32 nseed = htonl(state->seed);
|
|
||||||
uint32 nnbits = htonl(state->nbits);
|
|
||||||
uint32 nsize = htonl(state->size);
|
|
||||||
*buflen = sizeof(uint32)*3;
|
*buflen = sizeof(uint32)*3;
|
||||||
*buf = malloc(*buflen);
|
*buf = malloc(*buflen);
|
||||||
if (!*buf)
|
if (!*buf)
|
||||||
@ -172,9 +171,9 @@ void jenkins_state_dump(jenkins_state_t *state, char **buf, uint32 *buflen)
|
|||||||
*buflen = UINT_MAX;
|
*buflen = UINT_MAX;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
memcpy(*buf, &nseed, sizeof(uint32));
|
memcpy(*buf, &(state->seed), sizeof(uint32));
|
||||||
memcpy(*buf + sizeof(uint32), &nnbits, sizeof(uint32));
|
memcpy(*buf + sizeof(uint32), &(state->nbits), sizeof(uint32));
|
||||||
memcpy(*buf + sizeof(uint32)*2, &nsize, sizeof(uint32));
|
memcpy(*buf + sizeof(uint32)*2, &(state->size), sizeof(uint32));
|
||||||
DEBUGP("Dumped jenkins state with seed %u\n", state->seed);
|
DEBUGP("Dumped jenkins state with seed %u\n", state->seed);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
@ -182,9 +181,9 @@ void jenkins_state_dump(jenkins_state_t *state, char **buf, uint32 *buflen)
|
|||||||
jenkins_state_t *jenkins_state_load(const char *buf, uint32 buflen)
|
jenkins_state_t *jenkins_state_load(const char *buf, uint32 buflen)
|
||||||
{
|
{
|
||||||
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
||||||
state->seed = ntohl(*(uint32 *)buf);
|
state->seed = *(uint32 *)buf;
|
||||||
state->nbits = ntohl(*(((uint32 *)buf) + 1));
|
state->nbits = *(((uint32 *)buf) + 1);
|
||||||
state->size = ntohl(*(((uint32 *)buf) + 2));
|
state->size = *(((uint32 *)buf) + 2);
|
||||||
state->hashfunc = HASH_JENKINS;
|
state->hashfunc = HASH_JENKINS;
|
||||||
DEBUGP("Loaded jenkins state with seed %u\n", state->seed);
|
DEBUGP("Loaded jenkins state with seed %u\n", state->seed);
|
||||||
return state;
|
return state;
|
||||||
|
22
src/main.c
22
src/main.c
@ -8,7 +8,14 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include "cmph.h"
|
#include "cmph.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "../config.h"
|
#include "../wingetopt.h"
|
||||||
|
|
||||||
|
#ifdef WIN32
|
||||||
|
#define VERSION "0.2"
|
||||||
|
#else
|
||||||
|
#include "config.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void usage(const char *prg)
|
void usage(const char *prg)
|
||||||
{
|
{
|
||||||
@ -47,7 +54,7 @@ static int key_read(void *data, char **key, uint32 *keylen)
|
|||||||
if (feof(fd)) return -1;
|
if (feof(fd)) return -1;
|
||||||
*key = (char *)realloc(*key, *keylen + strlen(buf) + 1);
|
*key = (char *)realloc(*key, *keylen + strlen(buf) + 1);
|
||||||
memcpy(*key + *keylen, buf, strlen(buf));
|
memcpy(*key + *keylen, buf, strlen(buf));
|
||||||
*keylen += strlen(buf);
|
*keylen += (uint32)strlen(buf);
|
||||||
if (buf[strlen(buf) - 1] != '\n') continue;
|
if (buf[strlen(buf) - 1] != '\n') continue;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -76,7 +83,7 @@ static uint32 count_keys(FILE *fd)
|
|||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
char buf[BUFSIZ];
|
char buf[BUFSIZ];
|
||||||
char *c = fgets(buf, BUFSIZ, fd);
|
fgets(buf, BUFSIZ, fd);
|
||||||
if (feof(fd)) break;
|
if (feof(fd)) break;
|
||||||
if (buf[strlen(buf) - 1] != '\n') continue;
|
if (buf[strlen(buf) - 1] != '\n') continue;
|
||||||
++count;
|
++count;
|
||||||
@ -209,7 +216,7 @@ int main(int argc, char **argv)
|
|||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
keys_file = argv[optind];
|
keys_file = argv[optind];
|
||||||
if (seed == UINT_MAX) seed = time(NULL);
|
if (seed == UINT_MAX) seed = (uint32)time(NULL);
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
if (mphf_file == NULL)
|
if (mphf_file == NULL)
|
||||||
@ -219,7 +226,7 @@ int main(int argc, char **argv)
|
|||||||
memcpy(mphf_file + strlen(keys_file), ".mph\0", 5);
|
memcpy(mphf_file + strlen(keys_file), ".mph\0", 5);
|
||||||
}
|
}
|
||||||
|
|
||||||
keys_fd = fopen64(keys_file, "r");
|
keys_fd = fopen(keys_file, "r");
|
||||||
if (keys_fd == NULL)
|
if (keys_fd == NULL)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Unable to open file %s: %s\n", keys_file, strerror(errno));
|
fprintf(stderr, "Unable to open file %s: %s\n", keys_file, strerror(errno));
|
||||||
@ -227,7 +234,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
source.data = (void *)keys_fd;
|
source.data = (void *)keys_fd;
|
||||||
if (seed == UINT_MAX) seed = time(NULL);
|
if (seed == UINT_MAX) seed = (uint32)time(NULL);
|
||||||
if(nkeys == UINT_MAX) source.nkeys = count_keys(keys_fd);
|
if(nkeys == UINT_MAX) source.nkeys = count_keys(keys_fd);
|
||||||
else source.nkeys = nkeys;
|
else source.nkeys = nkeys;
|
||||||
source.read = key_read;
|
source.read = key_read;
|
||||||
@ -242,7 +249,8 @@ int main(int argc, char **argv)
|
|||||||
if (nhashes) mph_set_hashfuncs(mph, hashes);
|
if (nhashes) mph_set_hashfuncs(mph, hashes);
|
||||||
mph_set_verbosity(mph, verbosity);
|
mph_set_verbosity(mph, verbosity);
|
||||||
if(mph_algo == MPH_BMZ && c >= 2.0) c=1.15;
|
if(mph_algo == MPH_BMZ && c >= 2.0) c=1.15;
|
||||||
mphf = mph_create(mph, c);
|
if (c != 0) mph_set_graphsize(mph, c);
|
||||||
|
mphf = mph_create(mph);
|
||||||
|
|
||||||
if (mphf == NULL)
|
if (mphf == NULL)
|
||||||
{
|
{
|
||||||
|
@ -15,9 +15,9 @@ void sdbm_state_destroy(sdbm_state_t *state)
|
|||||||
|
|
||||||
uint32 sdbm_hash(sdbm_state_t *state, const char *k, uint32 keylen)
|
uint32 sdbm_hash(sdbm_state_t *state, const char *k, uint32 keylen)
|
||||||
{
|
{
|
||||||
register unsigned int hash = 0;
|
register uint32 hash = 0;
|
||||||
const unsigned char *ptr = k;
|
const unsigned char *ptr = k;
|
||||||
int i = 0;
|
uint32 i = 0;
|
||||||
|
|
||||||
while(i < keylen) {
|
while(i < keylen) {
|
||||||
hash = *ptr + (hash << 6) + (hash << 16) - hash;
|
hash = *ptr + (hash << 6) + (hash << 16) - hash;
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
#include "vqueue.h"
|
#include "vqueue.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <stdlib.h>
|
||||||
struct __vqueue_t
|
struct __vqueue_t
|
||||||
{
|
{
|
||||||
uint32 * values;
|
uint32 * values;
|
||||||
|
Loading…
Reference in New Issue
Block a user