Merge commit 'efe08b8080d0696bf388b21'

This commit is contained in:
Davi Reis 2014-06-06 12:00:56 -03:00
commit c09a1f64ea
4 changed files with 20 additions and 13 deletions

View File

@ -84,7 +84,7 @@ cmph_t *bmz8_new(cmph_config_t *mph, double c)
bmz8->graph = graph_new(bmz8->n, bmz8->m);
DEBUGP("Created graph\n");
bmz8->hashes = (hash_state_t **)malloc(sizeof(hash_state_t *)*3);
bmz8->hashes = (hash_state_t **)calloc(3,sizeof(hash_state_t *));
for(i = 0; i < 3; ++i) bmz8->hashes[i] = NULL;
do
@ -101,18 +101,22 @@ cmph_t *bmz8_new(cmph_config_t *mph, double c)
{
int ok;
DEBUGP("hash function 1\n");
if (bmz8->hashes[0])
hash_state_destroy(bmz8->hashes[0]);
bmz8->hashes[0] = hash_state_new(bmz8->hashfuncs[0], bmz8->n);
DEBUGP("hash function 2\n");
if (bmz8->hashes[1])
bmz8->hashes[1] = NULL;
bmz8->hashes[1] = hash_state_new(bmz8->hashfuncs[1], bmz8->n);
DEBUGP("Generating edges\n");
ok = bmz8_gen_edges(mph);
if (!ok)
{
--iterations;
hash_state_destroy(bmz8->hashes[0]);
bmz8->hashes[0] = NULL;
hash_state_destroy(bmz8->hashes[1]);
bmz8->hashes[1] = NULL;
// hash_state_destroy(bmz8->hashes[0]);
// bmz8->hashes[0] = NULL;
// hash_state_destroy(bmz8->hashes[1]);
// bmz8->hashes[1] = NULL;
DEBUGP("%u iterations remaining\n", iterations);
if (mph->verbosity)
{

View File

@ -269,7 +269,7 @@ cmph_t *fch_new(cmph_config_t *mph, double c)
{
fprintf(stderr, "Entering mapping step for mph creation of %u keys\n", fch->m);
}
if (buckets) fch_buckets_destroy(buckets);
if (buckets) fch_buckets_destroy(buckets, mph);
buckets = mapping(mph);
if (mph->verbosity)
{
@ -285,7 +285,7 @@ cmph_t *fch_new(cmph_config_t *mph, double c)
iterations--;
} while(restart_mapping && iterations > 0);
if (buckets) fch_buckets_destroy(buckets);
if (buckets) fch_buckets_destroy(buckets, mph);
if (sorted_indexes) free (sorted_indexes);
if (iterations == 0) return NULL;
mphf = (cmph_t *)malloc(sizeof(cmph_t));

View File

@ -1,5 +1,6 @@
#include "vqueue.h"
#include "fch_buckets.h"
#include "cmph_structs.h"
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
@ -28,13 +29,14 @@ static void fch_bucket_new(fch_bucket_t *bucket)
bucket->capacity = 0;
}
static void fch_bucket_destroy(fch_bucket_t *bucket)
static void fch_bucket_destroy(fch_bucket_t *bucket, cmph_config_t *mph)
{
cmph_uint32 i;
assert(bucket);
for (i = 0; i < bucket->size; i++)
{
free((bucket->entries + i)->value);
fch_bucket_entry_t * entry = bucket->entries + i;
mph->key_source->dispose(mph->key_source->data, entry->value, entry->length);
}
free(bucket->entries);
}
@ -205,10 +207,10 @@ void fch_buckets_print(fch_buckets_t * buckets)
for (i = 0; i < buckets->nbuckets; i++) fch_bucket_print(buckets->values + i, i);
}
void fch_buckets_destroy(fch_buckets_t * buckets)
void fch_buckets_destroy(fch_buckets_t * buckets, cmph_config_t *mph)
{
cmph_uint32 i;
for (i = 0; i < buckets->nbuckets; i++) fch_bucket_destroy(buckets->values + i);
for (i = 0; i < buckets->nbuckets; i++) fch_bucket_destroy(buckets->values + i, mph);
free(buckets->values);
free(buckets);
}

View File

@ -2,6 +2,7 @@
#define __CMPH_FCH_BUCKETS_H__
#include "cmph_types.h"
#include "cmph.h"
typedef struct __fch_buckets_t fch_buckets_t;
fch_buckets_t * fch_buckets_new(cmph_uint32 nbuckets);
@ -26,5 +27,5 @@ cmph_uint32 * fch_buckets_get_indexes_sorted_by_size(fch_buckets_t * buckets);
void fch_buckets_print(fch_buckets_t * buckets);
void fch_buckets_destroy(fch_buckets_t * buckets);
void fch_buckets_destroy(fch_buckets_t * buckets, cmph_config_t* mph);
#endif