summaryrefslogtreecommitdiff
path: root/girepository/cmph/bmz.c
diff options
context:
space:
mode:
Diffstat (limited to 'girepository/cmph/bmz.c')
-rw-r--r--girepository/cmph/bmz.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/girepository/cmph/bmz.c b/girepository/cmph/bmz.c
index 9c6cea00..9573825a 100644
--- a/girepository/cmph/bmz.c
+++ b/girepository/cmph/bmz.c
@@ -450,6 +450,10 @@ int bmz_dump(cmph_t *mphf, FILE *fd)
cmph_uint32 two = 2; //number of hash functions
bmz_data_t *data = (bmz_data_t *)mphf->data;
register size_t nbytes;
+#ifdef DEBUG
+ cmph_uint32 i;
+#endif
+
__cmph_dump(mphf, fd);
nbytes = fwrite(&two, sizeof(cmph_uint32), (size_t)1, fd);
@@ -470,12 +474,11 @@ int bmz_dump(cmph_t *mphf, FILE *fd)
nbytes = fwrite(&(data->m), sizeof(cmph_uint32), (size_t)1, fd);
nbytes = fwrite(data->g, sizeof(cmph_uint32)*(data->n), (size_t)1, fd);
- if (nbytes == 0 && ferror(fd)) {
+ if (nbytes == 0 && ferror(fd)) {
fprintf(stderr, "ERROR: %s\n", strerror(errno));
return 0;
}
#ifdef DEBUG
- cmph_uint32 i;
fprintf(stderr, "G: ");
for (i = 0; i < data->n; ++i) fprintf(stderr, "%u ", data->g[i]);
fprintf(stderr, "\n");
@@ -515,10 +518,11 @@ void bmz_load(FILE *f, cmph_t *mphf)
bmz->g = (cmph_uint32 *)malloc(sizeof(cmph_uint32)*bmz->n);
nbytes = fread(bmz->g, bmz->n*sizeof(cmph_uint32), (size_t)1, f);
- if (nbytes == 0 && ferror(f)) {
+ if (nbytes == 0 && ferror(f)) {
fprintf(stderr, "ERROR: %s\n", strerror(errno));
return;
}
+
#ifdef DEBUG
fprintf(stderr, "G: ");
for (i = 0; i < bmz->n; ++i) fprintf(stderr, "%u ", bmz->g[i]);
@@ -559,6 +563,7 @@ void bmz_pack(cmph_t *mphf, void *packed_mphf)
bmz_data_t *data = (bmz_data_t *)mphf->data;
cmph_uint8 * ptr = packed_mphf;
+ CMPH_HASH h2_type;
// packing h1 type
CMPH_HASH h1_type = hash_get_type(data->hashes[0]);
@@ -570,7 +575,7 @@ void bmz_pack(cmph_t *mphf, void *packed_mphf)
ptr += hash_state_packed_size(h1_type);
// packing h2 type
- CMPH_HASH h2_type = hash_get_type(data->hashes[1]);
+ h2_type = hash_get_type(data->hashes[1]);
*((cmph_uint32 *) ptr) = h2_type;
ptr += sizeof(cmph_uint32);
@@ -612,18 +617,22 @@ cmph_uint32 bmz_search_packed(void *packed_mphf, const char *key, cmph_uint32 ke
{
register cmph_uint8 *h1_ptr = packed_mphf;
register CMPH_HASH h1_type = *((cmph_uint32 *)h1_ptr);
+ register cmph_uint8 *h2_ptr;
+ register CMPH_HASH h2_type;
+ register cmph_uint32 *g_ptr, n, h1, h2;
+
h1_ptr += 4;
- register cmph_uint8 *h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
- register CMPH_HASH h2_type = *((cmph_uint32 *)h2_ptr);
+ h2_ptr = h1_ptr + hash_state_packed_size(h1_type);
+ h2_type = *((cmph_uint32 *)h2_ptr);
h2_ptr += 4;
- register cmph_uint32 *g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));
+ g_ptr = (cmph_uint32 *)(h2_ptr + hash_state_packed_size(h2_type));
- register cmph_uint32 n = *g_ptr++;
+ n = *g_ptr++;
- register cmph_uint32 h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n;
- register cmph_uint32 h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n;
+ h1 = hash_packed(h1_ptr, h1_type, key, keylen) % n;
+ h2 = hash_packed(h2_ptr, h2_type, key, keylen) % n;
if (h1 == h2 && ++h2 > n) h2 = 0;
return (g_ptr[h1] + g_ptr[h2]);
}