it was fixed more mistakes in BRZ algorithm
This commit is contained in:
parent
5212c7d5f3
commit
be73e6b2a4
47
src/brz.c
47
src/brz.c
|
@ -19,7 +19,7 @@
|
|||
|
||||
static int brz_before_gen_graphs(cmph_config_t *mph, cmph_uint32 * disksize, cmph_uint32 * diskoffset);
|
||||
static void brz_gen_graphs(cmph_config_t *mph, cmph_uint32 * disksize, cmph_uint32 * diskoffset, FILE * graphs_fd);
|
||||
static char ** brz_read_keys_vd(FILE * graphs_fd, cmph_uint8 nkeys, cmph_uint32 h3);
|
||||
static char ** brz_read_keys_vd(FILE * graphs_fd, cmph_uint8 nkeys);
|
||||
static void brz_destroy_keys_vd(char ** keys_vd, cmph_uint8 nkeys);
|
||||
static void brz_copy_partial_mphf(brz_config_data_t *brz, bmz_data_t * bmzf, cmph_uint32 index);
|
||||
|
||||
|
@ -128,7 +128,8 @@ cmph_t *brz_new(cmph_config_t *mph, float c)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
graphs_fd = fopen("/colecao/fbotelho/cmph.tmp", "wb");
|
||||
// graphs_fd = fopen("/colecao/fbotelho/cmph.tmp", "wb");
|
||||
graphs_fd = fopen("cmph.tmp", "wb");
|
||||
if (graphs_fd == NULL)
|
||||
{
|
||||
free(brz->size);
|
||||
|
@ -144,7 +145,8 @@ cmph_t *brz_new(cmph_config_t *mph, float c)
|
|||
free(diskoffset);
|
||||
DEBUGP("Graphs generated\n");
|
||||
fclose(graphs_fd);
|
||||
graphs_fd = fopen("/colecao/fbotelho/cmph.tmp", "rb");
|
||||
// graphs_fd = fopen("/colecao/fbotelho/cmph.tmp", "rb");
|
||||
graphs_fd = fopen("cmph.tmp", "rb");
|
||||
// codigo do algoritmo...
|
||||
brz->h1 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
|
||||
brz->h2 = (hash_state_t **)malloc(sizeof(hash_state_t *)*brz->k);
|
||||
|
@ -155,7 +157,7 @@ cmph_t *brz_new(cmph_config_t *mph, float c)
|
|||
cmph_uint32 j;
|
||||
bmz_data_t * bmzf = NULL;
|
||||
if (brz->size[i] == 0) continue;
|
||||
keys_vd = brz_read_keys_vd(graphs_fd, brz->size[i], i);
|
||||
keys_vd = brz_read_keys_vd(graphs_fd, brz->size[i]);
|
||||
// Source of keys
|
||||
source = cmph_io_vector_adapter(keys_vd, (cmph_uint32)brz->size[i]);
|
||||
config = cmph_config_new(source);
|
||||
|
@ -214,11 +216,11 @@ static int brz_before_gen_graphs(cmph_config_t *mph, cmph_uint32 * disksize, cmp
|
|||
char *key;
|
||||
mph->key_source->read(mph->key_source->data, &key, &keylen);
|
||||
h3 = hash(brz->h3, key, keylen) % brz->k;
|
||||
if(h3 == 6)
|
||||
{
|
||||
DEBUGP("key = %s\n", key);
|
||||
DEBUGP("keylen = %u\n", keylen + 1);
|
||||
}
|
||||
// if(h3 == 6)
|
||||
// {
|
||||
// DEBUGP("key = %s\n", key);
|
||||
// DEBUGP("keylen = %u\n", keylen + 1);
|
||||
// }
|
||||
|
||||
mph->key_source->dispose(mph->key_source->data, key, keylen);
|
||||
if (brz->size[h3] == 255) return 0;
|
||||
|
@ -230,13 +232,13 @@ static int brz_before_gen_graphs(cmph_config_t *mph, cmph_uint32 * disksize, cmp
|
|||
// }
|
||||
|
||||
}
|
||||
fprintf(stderr, "size:%u offset: %u\n", brz->size[0], brz->offset[0]);
|
||||
// DEBUGP("size:%u offset: %u\n", brz->size[0], brz->offset[0]);
|
||||
for (e = 1; e < brz->k; ++e)
|
||||
{
|
||||
brz->offset[e] = brz->size[e-1] + brz->offset[e-1];
|
||||
diskoffset[e] = disksize[e-1] + diskoffset[e-1];
|
||||
DEBUGP("disksize[%u]=%u diskoffset[%u]: %u\n", e, disksize[e], e, diskoffset[e]);
|
||||
DEBUGP("size[%u]=%u offset[%u]: %u\n", e, brz->size[e], e, brz->offset[e]);
|
||||
/* DEBUGP("disksize[%u]=%u diskoffset[%u]: %u\n", e, disksize[e], e, diskoffset[e]);
|
||||
DEBUGP("size[%u]=%u offset[%u]: %u\n", e, brz->size[e], e, brz->offset[e]);*/
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
@ -255,23 +257,23 @@ static void brz_gen_graphs(cmph_config_t *mph, cmph_uint32 * disksize, cmph_uint
|
|||
char *key;
|
||||
mph->key_source->read(mph->key_source->data, &key, &keylen);
|
||||
h3 = hash(brz->h3, key, keylen) % brz->k;
|
||||
if(h3 == 6)
|
||||
/* if(h3 == 6)
|
||||
{
|
||||
DEBUGP("key = %s\n", key);
|
||||
DEBUGP("keylen = %u\n", keylen + 1);
|
||||
}
|
||||
}*/
|
||||
fseek(graphs_fd, diskoffset[h3], SEEK_SET);
|
||||
fwrite(key, sizeof(char), keylen + 1, graphs_fd);
|
||||
if(h3 == 6)
|
||||
/* if(h3 == 6)
|
||||
{
|
||||
DEBUGP("diskoffset[%u]=%u \n", h3, diskoffset[h3]);
|
||||
}
|
||||
}*/
|
||||
diskoffset[h3] = diskoffset[h3] + keylen + 1;
|
||||
mph->key_source->dispose(mph->key_source->data, key, keylen);
|
||||
}
|
||||
}
|
||||
|
||||
static char ** brz_read_keys_vd(FILE * graphs_fd, cmph_uint8 nkeys, cmph_uint32 h3)
|
||||
static char ** brz_read_keys_vd(FILE * graphs_fd, cmph_uint8 nkeys)
|
||||
{
|
||||
char ** keys_vd = (char **)malloc(sizeof(char *)*nkeys);
|
||||
cmph_uint8 i;
|
||||
|
@ -291,7 +293,6 @@ static char ** brz_read_keys_vd(FILE * graphs_fd, cmph_uint8 nkeys, cmph_uint32
|
|||
}
|
||||
keys_vd[i] = (char *)malloc(strlen(buf) + 1);
|
||||
strcpy(keys_vd[i], buf);
|
||||
if(h3 == 6) DEBUGP("key = %s\n", keys_vd[i]);
|
||||
free(buf);
|
||||
}
|
||||
return keys_vd;
|
||||
|
@ -311,8 +312,8 @@ static void brz_copy_partial_mphf(brz_config_data_t *brz, bmz_data_t * bmzf, cmp
|
|||
{
|
||||
brz->g[index][i] = (cmph_uint8) bmzf->g[i];
|
||||
}
|
||||
brz->h1[index] = bmzf->hashes[0];
|
||||
brz->h2[index] = bmzf->hashes[1];
|
||||
brz->h1[index] = hash_state_copy(bmzf->hashes[0]);
|
||||
brz->h2[index] = hash_state_copy(bmzf->hashes[1]);
|
||||
}
|
||||
|
||||
int brz_dump(cmph_t *mphf, FILE *fd)
|
||||
|
@ -411,19 +412,13 @@ void brz_destroy(cmph_t *mphf)
|
|||
{
|
||||
cmph_uint32 i;
|
||||
brz_data_t *data = (brz_data_t *)mphf->data;
|
||||
fprintf(stderr, "MERDAAAAAA %u\n", data->h3->hashfunc);
|
||||
for(i = 0; i < data->k; i++)
|
||||
{
|
||||
free(data->g[i]);
|
||||
fprintf(stderr, "MERDAAAAAA1 %u\n", data->h3->hashfunc);
|
||||
hash_state_destroy(data->h1[i]);
|
||||
fprintf(stderr, "MERDAAAAAA2 %u\n", data->h3->hashfunc);
|
||||
hash_state_destroy(data->h2[i]);
|
||||
fprintf(stderr, "MERDAAAAAA3 %u\n", data->h3->hashfunc);
|
||||
}
|
||||
fprintf(stderr, "MERDAAAAAA %u\n", data->h3->hashfunc);
|
||||
hash_state_destroy(data->h3);
|
||||
fprintf(stderr, "MERDAAAAAA1FAB\n");
|
||||
free(data->g);
|
||||
free(data->h1);
|
||||
free(data->h2);
|
||||
|
|
|
@ -34,6 +34,13 @@ void djb2_state_dump(djb2_state_t *state, char **buf, cmph_uint32 *buflen)
|
|||
return;
|
||||
}
|
||||
|
||||
djb2_state_t *djb2_state_copy(djb2_state_t *src_state)
|
||||
{
|
||||
djb2_state_t *dest_state = (djb2_state_t *)malloc(sizeof(djb2_state_t));
|
||||
dest_state->hashfunc = src_state->hashfunc;
|
||||
return dest_state;
|
||||
}
|
||||
|
||||
djb2_state_t *djb2_state_load(const char *buf, cmph_uint32 buflen)
|
||||
{
|
||||
djb2_state_t *state = (djb2_state_t *)malloc(sizeof(djb2_state_t));
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef struct __djb2_state_t
|
|||
djb2_state_t *djb2_state_new();
|
||||
cmph_uint32 djb2_hash(djb2_state_t *state, const char *k, cmph_uint32 keylen);
|
||||
void djb2_state_dump(djb2_state_t *state, char **buf, cmph_uint32 *buflen);
|
||||
djb2_state_t *djb2_state_copy(djb2_state_t *src_state);
|
||||
djb2_state_t *djb2_state_load(const char *buf, cmph_uint32 buflen);
|
||||
void djb2_state_destroy(djb2_state_t *state);
|
||||
|
||||
|
|
|
@ -38,6 +38,13 @@ void fnv_state_dump(fnv_state_t *state, char **buf, cmph_uint32 *buflen)
|
|||
return;
|
||||
}
|
||||
|
||||
fnv_state_t * fnv_state_copy(fnv_state_t *src_state)
|
||||
{
|
||||
fnv_state_t *dest_state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
|
||||
dest_state->hashfunc = src_state->hashfunc;
|
||||
return dest_state;
|
||||
}
|
||||
|
||||
fnv_state_t *fnv_state_load(const char *buf, cmph_uint32 buflen)
|
||||
{
|
||||
fnv_state_t *state = (fnv_state_t *)malloc(sizeof(fnv_state_t));
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef struct __fnv_state_t
|
|||
fnv_state_t *fnv_state_new();
|
||||
cmph_uint32 fnv_hash(fnv_state_t *state, const char *k, cmph_uint32 keylen);
|
||||
void fnv_state_dump(fnv_state_t *state, char **buf, cmph_uint32 *buflen);
|
||||
fnv_state_t *fnv_state_copy(fnv_state_t *src_state);
|
||||
fnv_state_t *fnv_state_load(const char *buf, cmph_uint32 buflen);
|
||||
void fnv_state_destroy(fnv_state_t *state);
|
||||
|
||||
|
|
24
src/hash.c
24
src/hash.c
|
@ -86,6 +86,30 @@ void hash_state_dump(hash_state_t *state, char **buf, cmph_uint32 *buflen)
|
|||
return;
|
||||
}
|
||||
|
||||
hash_state_t * hash_state_copy(hash_state_t *src_state)
|
||||
{
|
||||
hash_state_t *dest_state = NULL;
|
||||
switch (src_state->hashfunc)
|
||||
{
|
||||
case CMPH_HASH_JENKINS:
|
||||
dest_state = (hash_state_t *)jenkins_state_copy((jenkins_state_t *)src_state);
|
||||
break;
|
||||
case CMPH_HASH_DJB2:
|
||||
dest_state = (hash_state_t *)djb2_state_copy((djb2_state_t *)src_state);
|
||||
break;
|
||||
case CMPH_HASH_SDBM:
|
||||
dest_state = (hash_state_t *)sdbm_state_copy((sdbm_state_t *)src_state);
|
||||
break;
|
||||
case CMPH_HASH_FNV:
|
||||
dest_state = (hash_state_t *)fnv_state_copy((fnv_state_t *)src_state);
|
||||
break;
|
||||
default:
|
||||
assert(0);
|
||||
}
|
||||
dest_state->hashfunc = src_state->hashfunc;
|
||||
return dest_state;
|
||||
}
|
||||
|
||||
hash_state_t *hash_state_load(const char *buf, cmph_uint32 buflen)
|
||||
{
|
||||
cmph_uint32 i;
|
||||
|
|
|
@ -8,6 +8,7 @@ typedef union __hash_state_t hash_state_t;
|
|||
hash_state_t *hash_state_new(CMPH_HASH, cmph_uint32 hashsize);
|
||||
cmph_uint32 hash(hash_state_t *state, const char *key, cmph_uint32 keylen);
|
||||
void hash_state_dump(hash_state_t *state, char **buf, cmph_uint32 *buflen);
|
||||
hash_state_t * hash_state_copy(hash_state_t *src_state);
|
||||
hash_state_t *hash_state_load(const char *buf, cmph_uint32 buflen);
|
||||
void hash_state_destroy(hash_state_t *state);
|
||||
|
||||
|
|
|
@ -178,6 +178,17 @@ void jenkins_state_dump(jenkins_state_t *state, char **buf, cmph_uint32 *buflen)
|
|||
|
||||
return;
|
||||
}
|
||||
|
||||
jenkins_state_t *jenkins_state_copy(jenkins_state_t *src_state)
|
||||
{
|
||||
jenkins_state_t *dest_state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
||||
dest_state->hashfunc = src_state->hashfunc;
|
||||
dest_state->seed = src_state->seed;
|
||||
dest_state->nbits = src_state->nbits;
|
||||
dest_state->size = src_state->size;
|
||||
return dest_state;
|
||||
}
|
||||
|
||||
jenkins_state_t *jenkins_state_load(const char *buf, cmph_uint32 buflen)
|
||||
{
|
||||
jenkins_state_t *state = (jenkins_state_t *)malloc(sizeof(jenkins_state_t));
|
||||
|
|
|
@ -14,6 +14,7 @@ typedef struct __jenkins_state_t
|
|||
jenkins_state_t *jenkins_state_new(cmph_uint32 size); //size of hash table
|
||||
cmph_uint32 jenkins_hash(jenkins_state_t *state, const char *k, cmph_uint32 keylen);
|
||||
void jenkins_state_dump(jenkins_state_t *state, char **buf, cmph_uint32 *buflen);
|
||||
jenkins_state_t *jenkins_state_copy(jenkins_state_t *src_state);
|
||||
jenkins_state_t *jenkins_state_load(const char *buf, cmph_uint32 buflen);
|
||||
void jenkins_state_destroy(jenkins_state_t *state);
|
||||
|
||||
|
|
|
@ -34,6 +34,13 @@ void sdbm_state_dump(sdbm_state_t *state, char **buf, cmph_uint32 *buflen)
|
|||
return;
|
||||
}
|
||||
|
||||
sdbm_state_t *sdbm_state_copy(sdbm_state_t *src_state)
|
||||
{
|
||||
sdbm_state_t *dest_state = (sdbm_state_t *)malloc(sizeof(sdbm_state_t));
|
||||
dest_state->hashfunc = src_state->hashfunc;
|
||||
return dest_state;
|
||||
}
|
||||
|
||||
sdbm_state_t *sdbm_state_load(const char *buf, cmph_uint32 buflen)
|
||||
{
|
||||
sdbm_state_t *state = (sdbm_state_t *)malloc(sizeof(sdbm_state_t));
|
||||
|
|
|
@ -11,6 +11,7 @@ typedef struct __sdbm_state_t
|
|||
sdbm_state_t *sdbm_state_new();
|
||||
cmph_uint32 sdbm_hash(sdbm_state_t *state, const char *k, cmph_uint32 keylen);
|
||||
void sdbm_state_dump(sdbm_state_t *state, char **buf, cmph_uint32 *buflen);
|
||||
sdbm_state_t *sdbm_state_copy(sdbm_state_t *src_state);
|
||||
sdbm_state_t *sdbm_state_load(const char *buf, cmph_uint32 buflen);
|
||||
void sdbm_state_destroy(sdbm_state_t *state);
|
||||
|
||||
|
|
Loading…
Reference in New Issue