Fixed a lot of warnings. Added visual studio project. Make needed changes to work with windows.
This commit is contained in:
parent
69c177a494
commit
edcd5b670a
6
COPYING
6
COPYING
@ -2,7 +2,7 @@
|
|||||||
Version 2, June 1991
|
Version 2, June 1991
|
||||||
|
|
||||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
Everyone is permitted to copy and distribute verbatim copies
|
Everyone is permitted to copy and distribute verbatim copies
|
||||||
of this license document, but changing it is not allowed.
|
of this license document, but changing it is not allowed.
|
||||||
|
|
||||||
@ -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.
|
||||||
|
131
INSTALL
131
INSTALL
@ -1,9 +1,3 @@
|
|||||||
Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002 Free Software
|
|
||||||
Foundation, Inc.
|
|
||||||
|
|
||||||
This file is free documentation; the Free Software Foundation gives
|
|
||||||
unlimited permission to copy, distribute and modify it.
|
|
||||||
|
|
||||||
Basic Installation
|
Basic Installation
|
||||||
==================
|
==================
|
||||||
|
|
||||||
@ -14,27 +8,20 @@ various system-dependent variables used during compilation. It uses
|
|||||||
those values to create a `Makefile' in each directory of the package.
|
those values to create a `Makefile' in each directory of the package.
|
||||||
It may also create one or more `.h' files containing system-dependent
|
It may also create one or more `.h' files containing system-dependent
|
||||||
definitions. Finally, it creates a shell script `config.status' that
|
definitions. Finally, it creates a shell script `config.status' that
|
||||||
you can run in the future to recreate the current configuration, and a
|
you can run in the future to recreate the current configuration, a file
|
||||||
file `config.log' containing compiler output (useful mainly for
|
`config.cache' that saves the results of its tests to speed up
|
||||||
debugging `configure').
|
reconfiguring, and a file `config.log' containing compiler output
|
||||||
|
(useful mainly for debugging `configure').
|
||||||
It can also use an optional file (typically called `config.cache'
|
|
||||||
and enabled with `--cache-file=config.cache' or simply `-C') that saves
|
|
||||||
the results of its tests to speed up reconfiguring. (Caching is
|
|
||||||
disabled by default to prevent problems with accidental use of stale
|
|
||||||
cache files.)
|
|
||||||
|
|
||||||
If you need to do unusual things to compile the package, please try
|
If you need to do unusual things to compile the package, please try
|
||||||
to figure out how `configure' could check whether to do them, and mail
|
to figure out how `configure' could check whether to do them, and mail
|
||||||
diffs or instructions to the address given in the `README' so they can
|
diffs or instructions to the address given in the `README' so they can
|
||||||
be considered for the next release. If you are using the cache, and at
|
be considered for the next release. If at some point `config.cache'
|
||||||
some point `config.cache' contains results you don't want to keep, you
|
contains results you don't want to keep, you may remove or edit it.
|
||||||
may remove or edit it.
|
|
||||||
|
|
||||||
The file `configure.ac' (or `configure.in') is used to create
|
The file `configure.in' is used to create `configure' by a program
|
||||||
`configure' by a program called `autoconf'. You only need
|
called `autoconf'. You only need `configure.in' if you want to change
|
||||||
`configure.ac' if you want to change it or regenerate `configure' using
|
it or regenerate `configure' using a newer version of `autoconf'.
|
||||||
a newer version of `autoconf'.
|
|
||||||
|
|
||||||
The simplest way to compile this package is:
|
The simplest way to compile this package is:
|
||||||
|
|
||||||
@ -68,16 +55,14 @@ Compilers and Options
|
|||||||
=====================
|
=====================
|
||||||
|
|
||||||
Some systems require unusual options for compilation or linking that
|
Some systems require unusual options for compilation or linking that
|
||||||
the `configure' script does not know about. Run `./configure --help'
|
the `configure' script does not know about. You can give `configure'
|
||||||
for details on some of the pertinent environment variables.
|
initial values for variables by setting them in the environment. Using
|
||||||
|
a Bourne-compatible shell, you can do that on the command line like
|
||||||
|
this:
|
||||||
|
CC=c89 CFLAGS=-O2 LIBS=-lposix ./configure
|
||||||
|
|
||||||
You can give `configure' initial values for configuration parameters
|
Or on systems that have the `env' program, you can do it like this:
|
||||||
by setting variables in the command line or in the environment. Here
|
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
|
||||||
is an example:
|
|
||||||
|
|
||||||
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
|
|
||||||
|
|
||||||
*Note Defining Variables::, for more details.
|
|
||||||
|
|
||||||
Compiling For Multiple Architectures
|
Compiling For Multiple Architectures
|
||||||
====================================
|
====================================
|
||||||
@ -90,11 +75,11 @@ directory where you want the object files and executables to go and run
|
|||||||
the `configure' script. `configure' automatically checks for the
|
the `configure' script. `configure' automatically checks for the
|
||||||
source code in the directory that `configure' is in and in `..'.
|
source code in the directory that `configure' is in and in `..'.
|
||||||
|
|
||||||
If you have to use a `make' that does not support the `VPATH'
|
If you have to use a `make' that does not supports the `VPATH'
|
||||||
variable, you have to compile the package for one architecture at a
|
variable, you have to compile the package for one architecture at a time
|
||||||
time in the source code directory. After you have installed the
|
in the source code directory. After you have installed the package for
|
||||||
package for one architecture, use `make distclean' before reconfiguring
|
one architecture, use `make distclean' before reconfiguring for another
|
||||||
for another architecture.
|
architecture.
|
||||||
|
|
||||||
Installation Names
|
Installation Names
|
||||||
==================
|
==================
|
||||||
@ -137,32 +122,22 @@ you can use the `configure' options `--x-includes=DIR' and
|
|||||||
Specifying the System Type
|
Specifying the System Type
|
||||||
==========================
|
==========================
|
||||||
|
|
||||||
There may be some features `configure' cannot figure out
|
There may be some features `configure' can not figure out
|
||||||
automatically, but needs to determine by the type of machine the package
|
automatically, but needs to determine by the type of host the package
|
||||||
will run on. Usually, assuming the package is built to be run on the
|
will run on. Usually `configure' can figure that out, but if it prints
|
||||||
_same_ architectures, `configure' can figure that out, but if it prints
|
a message saying it can not guess the host type, give it the
|
||||||
a message saying it cannot guess the machine type, give it the
|
`--host=TYPE' option. TYPE can either be a short name for the system
|
||||||
`--build=TYPE' option. TYPE can either be a short name for the system
|
type, such as `sun4', or a canonical name with three fields:
|
||||||
type, such as `sun4', or a canonical name which has the form:
|
|
||||||
|
|
||||||
CPU-COMPANY-SYSTEM
|
CPU-COMPANY-SYSTEM
|
||||||
|
|
||||||
where SYSTEM can have one of these forms:
|
See the file `config.sub' for the possible values of each field. If
|
||||||
|
|
||||||
OS KERNEL-OS
|
|
||||||
|
|
||||||
See the file `config.sub' for the possible values of each field. If
|
|
||||||
`config.sub' isn't included in this package, then this package doesn't
|
`config.sub' isn't included in this package, then this package doesn't
|
||||||
need to know the machine type.
|
need to know the host type.
|
||||||
|
|
||||||
If you are _building_ compiler tools for cross-compiling, you should
|
If you are building compiler tools for cross-compiling, you can also
|
||||||
use the `--target=TYPE' option to select the type of system they will
|
use the `--target=TYPE' option to select the type of system they will
|
||||||
produce code for.
|
produce code for and the `--build=TYPE' option to select the type of
|
||||||
|
system on which you are compiling the package.
|
||||||
If you want to _use_ a cross compiler, that generates code for a
|
|
||||||
platform different from the build platform, you should specify the
|
|
||||||
"host" platform (i.e., that on which the generated programs will
|
|
||||||
eventually be run) with `--host=TYPE'.
|
|
||||||
|
|
||||||
Sharing Defaults
|
Sharing Defaults
|
||||||
================
|
================
|
||||||
@ -175,43 +150,19 @@ default values for variables like `CC', `cache_file', and `prefix'.
|
|||||||
`CONFIG_SITE' environment variable to the location of the site script.
|
`CONFIG_SITE' environment variable to the location of the site script.
|
||||||
A warning: not all `configure' scripts look for a site script.
|
A warning: not all `configure' scripts look for a site script.
|
||||||
|
|
||||||
Defining Variables
|
Operation Controls
|
||||||
==================
|
==================
|
||||||
|
|
||||||
Variables not defined in a site shell script can be set in the
|
|
||||||
environment passed to `configure'. However, some packages may run
|
|
||||||
configure again during the build, and the customized values of these
|
|
||||||
variables may be lost. In order to avoid this problem, you should set
|
|
||||||
them in the `configure' command line, using `VAR=value'. For example:
|
|
||||||
|
|
||||||
./configure CC=/usr/local2/bin/gcc
|
|
||||||
|
|
||||||
will cause the specified gcc to be used as the C compiler (unless it is
|
|
||||||
overridden in the site shell script).
|
|
||||||
|
|
||||||
`configure' Invocation
|
|
||||||
======================
|
|
||||||
|
|
||||||
`configure' recognizes the following options to control how it
|
`configure' recognizes the following options to control how it
|
||||||
operates.
|
operates.
|
||||||
|
|
||||||
`--help'
|
|
||||||
`-h'
|
|
||||||
Print a summary of the options to `configure', and exit.
|
|
||||||
|
|
||||||
`--version'
|
|
||||||
`-V'
|
|
||||||
Print the version of Autoconf used to generate the `configure'
|
|
||||||
script, and exit.
|
|
||||||
|
|
||||||
`--cache-file=FILE'
|
`--cache-file=FILE'
|
||||||
Enable the cache: use and save the results of the tests in FILE,
|
Use and save the results of the tests in FILE instead of
|
||||||
traditionally `config.cache'. FILE defaults to `/dev/null' to
|
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
|
||||||
disable caching.
|
debugging `configure'.
|
||||||
|
|
||||||
`--config-cache'
|
`--help'
|
||||||
`-C'
|
Print a summary of the options to `configure', and exit.
|
||||||
Alias for `--cache-file=config.cache'.
|
|
||||||
|
|
||||||
`--quiet'
|
`--quiet'
|
||||||
`--silent'
|
`--silent'
|
||||||
@ -224,6 +175,8 @@ operates.
|
|||||||
Look for the package's source code in directory DIR. Usually
|
Look for the package's source code in directory DIR. Usually
|
||||||
`configure' can determine that directory automatically.
|
`configure' can determine that directory automatically.
|
||||||
|
|
||||||
`configure' also accepts some other, not widely useful, options. Run
|
`--version'
|
||||||
`configure --help' for more details.
|
Print the version of Autoconf used to generate the `configure'
|
||||||
|
script, and exit.
|
||||||
|
|
||||||
|
`configure' also accepts some other, not widely useful, options.
|
||||||
|
@ -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
|
||||||
|
14
src/cmph.c
14
src/cmph.c
@ -61,25 +61,33 @@ void mph_set_hashfuncs(mph_t *mph, CMPH_HASH *hashfuncs)
|
|||||||
czech_mph_set_hashfuncs(mph, hashfuncs);
|
czech_mph_set_hashfuncs(mph, hashfuncs);
|
||||||
break;
|
break;
|
||||||
case MPH_BMZ: /* included -- Fabiano */
|
case MPH_BMZ: /* included -- Fabiano */
|
||||||
bmz_mph_set_hashfuncs(mph, hashfuncs);
|
bmz_mph_set_hashfuncs(mph, hashfuncs);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
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
|
||||||
};
|
};
|
||||||
|
|
||||||
|
38
src/czech.c
38
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;
|
||||||
|
14
src/graph.c
14
src/graph.c
@ -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])))
|
||||||
@ -52,7 +52,7 @@ graph_t *graph_new(uint32 nnodes, uint32 nedges)
|
|||||||
|
|
||||||
void graph_destroy(graph_t *graph)
|
void graph_destroy(graph_t *graph)
|
||||||
{
|
{
|
||||||
DEBUGP("Destroying graph\n");
|
DEBUGP("Destroying graph\n");
|
||||||
free(graph->edges);
|
free(graph->edges);
|
||||||
free(graph->first);
|
free(graph->first);
|
||||||
free(graph->next);
|
free(graph->next);
|
||||||
@ -103,7 +103,7 @@ void graph_add_edge(graph_t *g, uint32 v1, uint32 v2)
|
|||||||
|
|
||||||
static int check_edge(graph_t *g, uint32 e, uint32 v1, uint32 v2)
|
static int check_edge(graph_t *g, uint32 e, uint32 v1, uint32 v2)
|
||||||
{
|
{
|
||||||
DEBUGP("Checking edge %u %u looking for %u %u\n", g->edges[abs_edge(e, 0)], g->edges[abs_edge(e, 1)], v1, v2);
|
DEBUGP("Checking edge %u %u looking for %u %u\n", g->edges[abs_edge(e, 0)], g->edges[abs_edge(e, 1)], v1, v2);
|
||||||
if (g->edges[abs_edge(e, 0)] == v1 && g->edges[abs_edge(e, 1)] == v2) return 1;
|
if (g->edges[abs_edge(e, 0)] == v1 && g->edges[abs_edge(e, 1)] == v2) return 1;
|
||||||
if (g->edges[abs_edge(e, 0)] == v2 && g->edges[abs_edge(e, 1)] == v1) return 1;
|
if (g->edges[abs_edge(e, 0)] == v2 && g->edges[abs_edge(e, 1)] == v1) return 1;
|
||||||
return 0;
|
return 0;
|
||||||
@ -207,7 +207,7 @@ static void cyclic_del_edge(graph_t *g, uint32 v, char *deleted)
|
|||||||
if (!degree1) return;
|
if (!degree1) return;
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
DEBUGP("Deleting edge %u (%u->%u)\n", e, g->edges[abs_edge(e, 0)], g->edges[abs_edge(e, 1)]);
|
DEBUGP("Deleting edge %u (%u->%u)\n", e, g->edges[abs_edge(e, 0)], g->edges[abs_edge(e, 1)]);
|
||||||
SETBIT(deleted, abs_edge(e, 0));
|
SETBIT(deleted, abs_edge(e, 0));
|
||||||
|
|
||||||
v2 = g->edges[abs_edge(e, 0)];
|
v2 = g->edges[abs_edge(e, 0)];
|
||||||
@ -217,7 +217,7 @@ static void cyclic_del_edge(graph_t *g, uint32 v, char *deleted)
|
|||||||
degree1 = find_degree1_edge(g, v2, deleted, &e);
|
degree1 = find_degree1_edge(g, v2, deleted, &e);
|
||||||
if (degree1)
|
if (degree1)
|
||||||
{
|
{
|
||||||
DEBUGP("Inspecting vertex %u\n", v2);
|
DEBUGP("Inspecting vertex %u\n", v2);
|
||||||
v1 = v2;
|
v1 = v2;
|
||||||
}
|
}
|
||||||
else break;
|
else break;
|
||||||
@ -240,7 +240,7 @@ int graph_is_cyclic(graph_t *g)
|
|||||||
{
|
{
|
||||||
if (!(GETBIT(deleted, i)))
|
if (!(GETBIT(deleted, i)))
|
||||||
{
|
{
|
||||||
DEBUGP("Edge %u %u->%u was not deleted\n", i, g->edges[i], g->edges[i + g->nedges]);
|
DEBUGP("Edge %u %u->%u was not deleted\n", i, g->edges[i], g->edges[i + g->nedges]);
|
||||||
free(deleted);
|
free(deleted);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -261,7 +261,7 @@ void graph_obtain_critical_nodes(graph_t *g) /* included -- Fabiano*/
|
|||||||
char *deleted = (char *)malloc((g->nedges*sizeof(char))/8+1);
|
char *deleted = (char *)malloc((g->nedges*sizeof(char))/8+1);
|
||||||
memset(deleted, 0, g->nedges/8 + 1);
|
memset(deleted, 0, g->nedges/8 + 1);
|
||||||
free(g->critical_nodes);
|
free(g->critical_nodes);
|
||||||
g->critical_nodes = (uint8 *)malloc((g->nnodes*sizeof(uint8))/8 + 1);
|
g->critical_nodes = (uint8 *)malloc((g->nnodes*sizeof(uint8))/8 + 1);
|
||||||
g->ncritical_nodes = 0;
|
g->ncritical_nodes = 0;
|
||||||
memset(g->critical_nodes, 0, (g->nnodes*sizeof(uint8))/8 + 1);
|
memset(g->critical_nodes, 0, (g->nnodes*sizeof(uint8))/8 + 1);
|
||||||
DEBUGP("Looking for the 2-core in graph with %u vertices and %u edges\n", g->nnodes, g->nedges);
|
DEBUGP("Looking for the 2-core in graph with %u vertices and %u edges\n", g->nnodes, g->nedges);
|
||||||
|
@ -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;
|
||||||
|
24
src/main.c
24
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)
|
||||||
{
|
{
|
||||||
@ -265,7 +273,7 @@ int main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
uint8 * hashtable = NULL;
|
uint8 * hashtable = NULL;
|
||||||
mphf_fd = fopen(mphf_file, "r");
|
mphf_fd = fopen(mphf_file, "r");
|
||||||
if (mphf_fd == NULL)
|
if (mphf_fd == 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