Fixed small main.cc bug when -m parameter was in use.
This commit is contained in:
parent
c4bc326c4b
commit
dffa191e74
18
src/main.c
18
src/main.c
@ -187,6 +187,7 @@ int main(int argc, char **argv)
|
|||||||
if (seed == UINT_MAX) seed = (cmph_uint32)time(NULL);
|
if (seed == UINT_MAX) seed = (cmph_uint32)time(NULL);
|
||||||
srand(seed);
|
srand(seed);
|
||||||
|
|
||||||
|
int ret = 0;
|
||||||
if (mphf_file == NULL)
|
if (mphf_file == NULL)
|
||||||
{
|
{
|
||||||
mphf_file = (char *)malloc(strlen(keys_file) + 5);
|
mphf_file = (char *)malloc(strlen(keys_file) + 5);
|
||||||
@ -255,6 +256,7 @@ int main(int argc, char **argv)
|
|||||||
free(mphf_file);
|
free(mphf_file);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
cmph_uint32 siz = cmph_size(mphf);
|
||||||
hashtable = (cmph_uint8*)malloc(source->nkeys*sizeof(cmph_uint8));
|
hashtable = (cmph_uint8*)malloc(source->nkeys*sizeof(cmph_uint8));
|
||||||
memset(hashtable, 0, source->nkeys);
|
memset(hashtable, 0, source->nkeys);
|
||||||
//check all keys
|
//check all keys
|
||||||
@ -265,10 +267,16 @@ int main(int argc, char **argv)
|
|||||||
cmph_uint32 buflen = 0;
|
cmph_uint32 buflen = 0;
|
||||||
source->read(source->data, &buf, &buflen);
|
source->read(source->data, &buf, &buflen);
|
||||||
h = cmph_search(mphf, buf, buflen);
|
h = cmph_search(mphf, buf, buflen);
|
||||||
assert(h < source->nkeys);
|
if (!(h < siz))
|
||||||
if(hashtable[h])fprintf(stderr, "collision: %u\n",h);
|
{
|
||||||
assert(hashtable[h]==0);
|
fprintf(stderr, "Unknown key %*s in the input.\n", buflen, buf);
|
||||||
hashtable[h] = 1;
|
ret = 1;
|
||||||
|
} else if(hashtable[h])
|
||||||
|
{
|
||||||
|
fprintf(stderr, "Duplicated or unknown key %*s in the input\n", buflen, buf);
|
||||||
|
ret = 1;
|
||||||
|
} else hashtable[h] = 1;
|
||||||
|
|
||||||
if (verbosity)
|
if (verbosity)
|
||||||
{
|
{
|
||||||
printf("%s -> %u\n", buf, h);
|
printf("%s -> %u\n", buf, h);
|
||||||
@ -282,5 +290,5 @@ int main(int argc, char **argv)
|
|||||||
free(mphf_file);
|
free(mphf_file);
|
||||||
free(tmp_dir);
|
free(tmp_dir);
|
||||||
free(source);
|
free(source);
|
||||||
return 0;
|
return ret;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user