1
Fork 0

Fixed a lot of warnings. Added visual studio project. Make needed changes to work with windows.

main
davi 2005-01-18 12:18:51 +00:00
parent 69c177a494
commit edcd5b670a
20 changed files with 165 additions and 186 deletions

View File

@ -2,7 +2,7 @@
Version 2, June 1991
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
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.
<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
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
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'.
This is free software, and you are welcome to redistribute it
under certain conditions; type `show c' for details.

131
INSTALL
View File

@ -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
==================
@ -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.
It may also create one or more `.h' files containing system-dependent
definitions. Finally, it creates a shell script `config.status' that
you can run in the future to recreate the current configuration, 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.)
you can run in the future to recreate the current configuration, a file
`config.cache' that saves the results of its tests to speed up
reconfiguring, and a file `config.log' containing compiler output
(useful mainly for debugging `configure').
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
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
some point `config.cache' contains results you don't want to keep, you
may remove or edit it.
be considered for the next release. If at some point `config.cache'
contains results you don't want to keep, you may remove or edit it.
The file `configure.ac' (or `configure.in') is used to create
`configure' by a program called `autoconf'. You only need
`configure.ac' if you want to change it or regenerate `configure' using
a newer version of `autoconf'.
The file `configure.in' is used to create `configure' by a program
called `autoconf'. You only need `configure.in' if you want to change
it or regenerate `configure' using a newer version of `autoconf'.
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
the `configure' script does not know about. Run `./configure --help'
for details on some of the pertinent environment variables.
the `configure' script does not know about. You can give `configure'
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
by setting variables in the command line or in the environment. Here
is an example:
./configure CC=c89 CFLAGS=-O2 LIBS=-lposix
*Note Defining Variables::, for more details.
Or on systems that have the `env' program, you can do it like this:
env CPPFLAGS=-I/usr/local/include LDFLAGS=-s ./configure
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
source code in the directory that `configure' is in and in `..'.
If you have to use a `make' that does not support the `VPATH'
variable, you have to compile the package for one architecture at a
time in the source code directory. After you have installed the
package for one architecture, use `make distclean' before reconfiguring
for another architecture.
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 time
in the source code directory. After you have installed the package for
one architecture, use `make distclean' before reconfiguring for another
architecture.
Installation Names
==================
@ -137,32 +122,22 @@ you can use the `configure' options `--x-includes=DIR' and
Specifying the System Type
==========================
There may be some features `configure' cannot figure out
automatically, but needs to determine by the type of machine the package
will run on. Usually, assuming the package is built to be run on the
_same_ architectures, `configure' can figure that out, but if it prints
a message saying it cannot guess the machine type, give it the
`--build=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name which has the form:
There may be some features `configure' can not figure out
automatically, but needs to determine by the type of host the package
will run on. Usually `configure' can figure that out, but if it prints
a message saying it can not guess the host type, give it the
`--host=TYPE' option. TYPE can either be a short name for the system
type, such as `sun4', or a canonical name with three fields:
CPU-COMPANY-SYSTEM
where SYSTEM can have one of these forms:
OS KERNEL-OS
See the file `config.sub' for the possible values of each field. If
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
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
produce code for.
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'.
produce code for and the `--build=TYPE' option to select the type of
system on which you are compiling the package.
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.
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
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'
Enable the cache: use and save the results of the tests in FILE,
traditionally `config.cache'. FILE defaults to `/dev/null' to
disable caching.
Use and save the results of the tests in FILE instead of
`./config.cache'. Set FILE to `/dev/null' to disable caching, for
debugging `configure'.
`--config-cache'
`-C'
Alias for `--cache-file=config.cache'.
`--help'
Print a summary of the options to `configure', and exit.
`--quiet'
`--silent'
@ -224,6 +175,8 @@ operates.
Look for the package's source code in directory DIR. Usually
`configure' can determine that directory automatically.
`configure' also accepts some other, not widely useful, options. Run
`configure --help' for more details.
`--version'
Print the version of Autoconf used to generate the `configure'
script, and exit.
`configure' also accepts some other, not widely useful, options.

View File

@ -18,5 +18,5 @@ libcmph_la_SOURCES = debug.h\
libcmph_la_LDFLAGS = -version-info 0:0:0
cmph_SOURCES = main.c
cmph_SOURCES = main.c ../wingetopt.h ../wingetopt.c
cmph_LDADD = libcmph.la

View File

@ -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]);

View File

@ -14,5 +14,6 @@ mphf_t *bmz_mph_create(mph_t *mph, float bmz_c);
void bmz_mphf_load(FILE *f, mphf_t *mphf);
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);
#endif

View File

@ -61,25 +61,33 @@ void mph_set_hashfuncs(mph_t *mph, CMPH_HASH *hashfuncs)
czech_mph_set_hashfuncs(mph, hashfuncs);
break;
case MPH_BMZ: /* included -- Fabiano */
bmz_mph_set_hashfuncs(mph, hashfuncs);
bmz_mph_set_hashfuncs(mph, hashfuncs);
break;
default:
break;
}
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;
float c = mph->c;
switch (mph->algo)
{
case MPH_CZECH:
DEBUGP("Creating czech hash\n");
if (c == 0) c = 2.09;
mphf = czech_mph_create(mph, c);
break;
case MPH_BMZ: /* included -- Fabiano */
DEBUGP("Creating bmz hash\n");
if (c == 0) c = 1.15;
mphf = bmz_mph_create(mph, c);
break;
default:
@ -143,7 +151,7 @@ uint32 mphf_search(mphf_t *mphf, const char *key, uint32 keylen)
assert(0);
}
assert(0);
return;
return 0;
}
uint32 mphf_size(mphf_t *mphf)

View File

@ -27,8 +27,9 @@ typedef struct
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_verbosity(mph_t *mph, uint32 verbosity);
void mph_set_graphsize(mph_t *mph, float c);
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 **/
mphf_t *mphf_load(FILE *f);

View File

@ -13,6 +13,7 @@ mph_t *__mph_new(MPH_ALGO algo, key_source_t *key_source)
mph->algo = algo;
mph->key_source = key_source;
mph->verbosity = 0;
float c = 0;
return mph;
}
@ -24,7 +25,7 @@ void __mph_destroy(mph_t *mph)
void __mphf_dump(mphf_t *mphf, FILE *fd)
{
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);
}
mphf_t *__mphf_load(FILE *f)

View File

@ -10,6 +10,7 @@ struct __mph_t
MPH_ALGO algo;
key_source_t *key_source;
uint32 verbosity;
float c;
void *data; //algorithm dependent data
};

View File

@ -8,7 +8,6 @@
#include <stdio.h>
#include <assert.h>
#include <string.h>
#include <netinet/in.h>
//#define DEBUG
#include "debug.h"
@ -68,7 +67,7 @@ mphf_t *czech_mph_create(mph_t *mph, float c)
char *visited = NULL;
czech_mph_data_t *czech = (czech_mph_data_t *)mph->data;
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);
czech->graph = graph_new(czech->n, czech->m);
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 (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;
}
@ -216,39 +215,29 @@ int czech_mphf_dump(mphf_t *mphf, FILE *fd)
{
char *buf = NULL;
uint32 buflen;
uint32 nbuflen;
uint32 i;
uint32 two = htonl(2); //number of hash functions
uint32 two = 2; //number of hash functions
czech_mphf_data_t *data = (czech_mphf_data_t *)mphf->data;
uint32 nn, nm;
__mphf_dump(mphf, fd);
fwrite(&two, sizeof(uint32), 1, 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);
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
fprintf(stderr, "G: ");
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)
{
uint32 nhashes;
char fbuf[BUFSIZ];
char *buf = NULL;
uint32 buflen;
uint32 i;
hash_state_t *state;
czech_mphf_data_t *czech = (czech_mphf_data_t *)malloc(sizeof(czech_mphf_data_t));
DEBUGP("Loading czech mphf\n");
mphf->data = czech;
fread(&nhashes, sizeof(uint32), 1, f);
nhashes = ntohl(nhashes);
czech->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*(nhashes + 1));
czech->hashes[nhashes] = NULL;
DEBUGP("Reading %u hashes\n", nhashes);
@ -278,7 +264,6 @@ void czech_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);
@ -289,13 +274,10 @@ void czech_mphf_load(FILE *f, mphf_t *mphf)
DEBUGP("Reading m and n\n");
fread(&(czech->n), sizeof(uint32), 1, f);
czech->n = ntohl(czech->n);
fread(&(czech->m), sizeof(uint32), 1, f);
czech->m = ntohl(czech->m);
czech->g = (uint32 *)malloc(sizeof(uint32)*czech->n);
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
fprintf(stderr, "G: ");

View File

@ -14,5 +14,6 @@ mphf_t *czech_mph_create(mph_t *mph, float c);
void czech_mphf_load(FILE *f, mphf_t *mphf);
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);
#endif

View File

@ -1,15 +1,53 @@
#ifndef __MY_DEBUGC__
#define __MY_DEBUGC__
#ifdef DEBUGP
#undef DEBUGP
#endif
#ifdef __cplusplus
#include <cstdio>
#ifdef WIN32
#include <cstring>
#endif
#else
#include <stdio.h>
#ifdef WIN32
#include <string.h>
#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 WIN32
#define DEBUGP debugprintf
#else
#define DEBUGP(args...) do { fprintf(stderr, "%s:%d ", __FILE__, __LINE__); fprintf(stderr, ## args); } while(0)
#endif
#else
#ifdef WIN32
#define DEBUGP dummyprintf
#else
#define DEBUGP(args...)
#endif
#endif

View File

@ -15,9 +15,9 @@ void djb2_state_destroy(djb2_state_t *state)
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;
int i = 0;
uint32 i = 0;
while (i < keylen)
{
hash = hash*33 ^ *ptr;

View File

@ -10,7 +10,7 @@
//#define DEBUG
#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 SETBIT(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)
{
DEBUGP("Destroying graph\n");
DEBUGP("Destroying graph\n");
free(graph->edges);
free(graph->first);
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)
{
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)] == v2 && g->edges[abs_edge(e, 1)] == v1) return 1;
return 0;
@ -207,7 +207,7 @@ static void cyclic_del_edge(graph_t *g, uint32 v, char *deleted)
if (!degree1) return;
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));
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);
if (degree1)
{
DEBUGP("Inspecting vertex %u\n", v2);
DEBUGP("Inspecting vertex %u\n", v2);
v1 = v2;
}
else break;
@ -240,7 +240,7 @@ int graph_is_cyclic(graph_t *g)
{
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);
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);
memset(deleted, 0, g->nedges/8 + 1);
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;
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);

View File

@ -20,9 +20,10 @@ graph_t *graph_new(uint32 nnodes, uint32 nedges);
void graph_destroy(graph_t *graph);
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);
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);
uint32 graph_next_neighbor(graph_t *g, graph_iterator_t* it);

View File

@ -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);
DEBUGP("Algobuf is %u\n", *(uint32 *)algobuf);
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);
return;
}
@ -100,7 +100,7 @@ hash_state_t *hash_state_load(const char *buf, uint32 buflen)
}
}
if (hashfunc == HASH_COUNT) return NULL;
offset = strlen(hash_names[hashfunc]) + 1;
offset = (uint32)strlen(hash_names[hashfunc]) + 1;
switch (hashfunc)
{
case HASH_JENKINS:

View File

@ -1,9 +1,11 @@
#include "jenkins_hash.h"
#include <stdlib.h>
#ifdef WIN32
#define _USE_MATH_DEFINES //For M_LOG2E
#endif
#include <math.h>
#include <limits.h>
#include <string.h>
#include <netinet/in.h>
//#define DEBUG
#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));
DEBUGP("Initializing jenkins hash\n");
state->seed = rand() % size;
state->nbits = ceil(log(size)/M_LOG2E);
state->nbits = (uint32)ceil(log(size)/M_LOG2E);
state->size = size;
DEBUGP("Initialized jenkins with size %u, nbits %u and seed %u\n", size, state->nbits, state->seed);
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)
{
uint32 nseed = htonl(state->seed);
uint32 nnbits = htonl(state->nbits);
uint32 nsize = htonl(state->size);
*buflen = sizeof(uint32)*3;
*buf = malloc(*buflen);
if (!*buf)
@ -172,9 +171,9 @@ void jenkins_state_dump(jenkins_state_t *state, char **buf, uint32 *buflen)
*buflen = UINT_MAX;
return;
}
memcpy(*buf, &nseed, sizeof(uint32));
memcpy(*buf + sizeof(uint32), &nnbits, sizeof(uint32));
memcpy(*buf + sizeof(uint32)*2, &nsize, sizeof(uint32));
memcpy(*buf, &(state->seed), sizeof(uint32));
memcpy(*buf + sizeof(uint32), &(state->nbits), sizeof(uint32));
memcpy(*buf + sizeof(uint32)*2, &(state->size), sizeof(uint32));
DEBUGP("Dumped jenkins state with seed %u\n", state->seed);
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 *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
state->seed = ntohl(*(uint32 *)buf);
state->nbits = ntohl(*(((uint32 *)buf) + 1));
state->size = ntohl(*(((uint32 *)buf) + 2));
state->seed = *(uint32 *)buf;
state->nbits = *(((uint32 *)buf) + 1);
state->size = *(((uint32 *)buf) + 2);
state->hashfunc = HASH_JENKINS;
DEBUGP("Loaded jenkins state with seed %u\n", state->seed);
return state;

View File

@ -8,7 +8,14 @@
#include <assert.h>
#include "cmph.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)
{
@ -47,7 +54,7 @@ static int key_read(void *data, char **key, uint32 *keylen)
if (feof(fd)) return -1;
*key = (char *)realloc(*key, *keylen + strlen(buf) + 1);
memcpy(*key + *keylen, buf, strlen(buf));
*keylen += strlen(buf);
*keylen += (uint32)strlen(buf);
if (buf[strlen(buf) - 1] != '\n') continue;
break;
}
@ -76,7 +83,7 @@ static uint32 count_keys(FILE *fd)
while(1)
{
char buf[BUFSIZ];
char *c = fgets(buf, BUFSIZ, fd);
fgets(buf, BUFSIZ, fd);
if (feof(fd)) break;
if (buf[strlen(buf) - 1] != '\n') continue;
++count;
@ -209,7 +216,7 @@ int main(int argc, char **argv)
return 1;
}
keys_file = argv[optind];
if (seed == UINT_MAX) seed = time(NULL);
if (seed == UINT_MAX) seed = (uint32)time(NULL);
srand(seed);
if (mphf_file == NULL)
@ -219,7 +226,7 @@ int main(int argc, char **argv)
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)
{
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;
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);
else source.nkeys = nkeys;
source.read = key_read;
@ -242,7 +249,8 @@ int main(int argc, char **argv)
if (nhashes) mph_set_hashfuncs(mph, hashes);
mph_set_verbosity(mph, verbosity);
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)
{
@ -265,7 +273,7 @@ int main(int argc, char **argv)
}
else
{
uint8 * hashtable = NULL;
uint8 * hashtable = NULL;
mphf_fd = fopen(mphf_file, "r");
if (mphf_fd == NULL)
{

View File

@ -15,9 +15,9 @@ void sdbm_state_destroy(sdbm_state_t *state)
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;
int i = 0;
uint32 i = 0;
while(i < keylen) {
hash = *ptr + (hash << 6) + (hash << 16) - hash;

View File

@ -1,6 +1,7 @@
#include "vqueue.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
struct __vqueue_t
{
uint32 * values;