fixed problem where the FCH algorithm did not dispose the keys using the user supplied function specified in cmph_config_t.
This commit is contained in:
parent
a45235f886
commit
efe08b8080
@ -264,12 +264,12 @@ cmph_t *fch_new(cmph_config_t *mph, double c)
|
|||||||
fch->h2 = NULL;
|
fch->h2 = NULL;
|
||||||
fch->g = NULL;
|
fch->g = NULL;
|
||||||
do
|
do
|
||||||
{
|
{
|
||||||
if (mph->verbosity)
|
if (mph->verbosity)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Entering mapping step for mph creation of %u keys\n", fch->m);
|
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);
|
buckets = mapping(mph);
|
||||||
if (mph->verbosity)
|
if (mph->verbosity)
|
||||||
{
|
{
|
||||||
@ -285,7 +285,7 @@ cmph_t *fch_new(cmph_config_t *mph, double c)
|
|||||||
iterations--;
|
iterations--;
|
||||||
|
|
||||||
} while(restart_mapping && iterations > 0);
|
} 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 (sorted_indexes) free (sorted_indexes);
|
||||||
if (iterations == 0) return NULL;
|
if (iterations == 0) return NULL;
|
||||||
mphf = (cmph_t *)malloc(sizeof(cmph_t));
|
mphf = (cmph_t *)malloc(sizeof(cmph_t));
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
#include "vqueue.h"
|
#include "vqueue.h"
|
||||||
#include "fch_buckets.h"
|
#include "fch_buckets.h"
|
||||||
|
#include "cmph_structs.h"
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -28,13 +29,14 @@ static void fch_bucket_new(fch_bucket_t *bucket)
|
|||||||
bucket->capacity = 0;
|
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;
|
cmph_uint32 i;
|
||||||
assert(bucket);
|
assert(bucket);
|
||||||
for (i = 0; i < bucket->size; i++)
|
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);
|
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);
|
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;
|
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->values);
|
||||||
free(buckets);
|
free(buckets);
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
#define __CMPH_FCH_BUCKETS_H__
|
#define __CMPH_FCH_BUCKETS_H__
|
||||||
|
|
||||||
#include "cmph_types.h"
|
#include "cmph_types.h"
|
||||||
|
#include "cmph.h"
|
||||||
typedef struct __fch_buckets_t fch_buckets_t;
|
typedef struct __fch_buckets_t fch_buckets_t;
|
||||||
|
|
||||||
fch_buckets_t * fch_buckets_new(cmph_uint32 nbuckets);
|
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_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
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user