checking the bug reported by Ayat Dawood. It was fixed using his suggestion (if((bdz->r%2)==0) bdz->r+=1; // The new line)
This commit is contained in:
parent
cf0b25f6ee
commit
7835d6b3e6
@ -2,39 +2,40 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
// Create minimal perfect hash function from in-memory vector
|
// Create minimal perfect hash function from in-memory vector
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Creating a filled vector
|
|
||||||
unsigned int i = 0;
|
|
||||||
const char *vector[] = {"aaaaaaaaaa", "bbbbbbbbbb", "cccccccccc", "dddddddddd", "eeeeeeeeee",
|
|
||||||
"ffffffffff", "gggggggggg", "hhhhhhhhhh", "iiiiiiiiii", "jjjjjjjjjj"};
|
|
||||||
unsigned int nkeys = 10;
|
|
||||||
FILE* mphf_fd = fopen("temp.mph", "w");
|
|
||||||
// Source of keys
|
|
||||||
cmph_io_adapter_t *source = cmph_io_vector_adapter((char **)vector, nkeys);
|
|
||||||
|
|
||||||
//Create minimal perfect hash function using the default (chm) algorithm.
|
// Creating a filled vector
|
||||||
cmph_config_t *config = cmph_config_new(source);
|
unsigned int i = 0;
|
||||||
cmph_config_set_algo(config, CMPH_BRZ);
|
const char *vector[] = {"aaaaaaaaaa", "bbbbbbbbbb", "cccccccccc", "dddddddddd", "eeeeeeeeee",
|
||||||
cmph_config_set_mphf_fd(config, mphf_fd);
|
"ffffffffff", "gggggggggg", "hhhhhhhhhh", "iiiiiiiiii", "jjjjjjjjjj"};
|
||||||
cmph_t *hash = cmph_new(config);
|
unsigned int nkeys = 10;
|
||||||
cmph_config_destroy(config);
|
FILE* mphf_fd = fopen("temp.mph", "w");
|
||||||
|
// Source of keys
|
||||||
|
cmph_io_adapter_t *source = cmph_io_vector_adapter((char **)vector, nkeys);
|
||||||
|
|
||||||
|
//Create minimal perfect hash function using the default (chm) algorithm.
|
||||||
|
cmph_config_t *config = cmph_config_new(source);
|
||||||
|
cmph_config_set_algo(config, CMPH_BRZ);
|
||||||
|
cmph_config_set_mphf_fd(config, mphf_fd);
|
||||||
|
cmph_t *hash = cmph_new(config);
|
||||||
|
cmph_config_destroy(config);
|
||||||
cmph_dump(hash, mphf_fd);
|
cmph_dump(hash, mphf_fd);
|
||||||
cmph_destroy(hash);
|
cmph_destroy(hash);
|
||||||
fclose(mphf_fd);
|
fclose(mphf_fd);
|
||||||
|
|
||||||
//Find key
|
//Find key
|
||||||
mphf_fd = fopen("temp.mph", "r");
|
mphf_fd = fopen("temp.mph", "r");
|
||||||
hash = cmph_load(mphf_fd);
|
hash = cmph_load(mphf_fd);
|
||||||
while (i < nkeys) {
|
while (i < nkeys) {
|
||||||
const char *key = vector[i];
|
const char *key = vector[i];
|
||||||
unsigned int id = cmph_search(hash, key, (cmph_uint32)strlen(key));
|
unsigned int id = cmph_search(hash, key, (cmph_uint32)strlen(key));
|
||||||
fprintf(stderr, "key:%s -- hash:%u\n", key, id);
|
fprintf(stderr, "key:%s -- hash:%u\n", key, id);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Destroy hash
|
//Destroy hash
|
||||||
cmph_destroy(hash);
|
cmph_destroy(hash);
|
||||||
cmph_io_vector_adapter_destroy(source);
|
cmph_io_vector_adapter_destroy(source);
|
||||||
fclose(mphf_fd);
|
fclose(mphf_fd);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user