vector adapter example updated to be used with brz algorithm
This commit is contained in:
parent
9c3a26110c
commit
dafb408c10
@ -4,23 +4,38 @@
|
|||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// Creating a filled vector
|
// Creating a filled vector
|
||||||
|
unsigned int i = 0;
|
||||||
const char *vector[] = {"aaaaaaaaaa", "bbbbbbbbbb", "cccccccccc", "dddddddddd", "eeeeeeeeee",
|
const char *vector[] = {"aaaaaaaaaa", "bbbbbbbbbb", "cccccccccc", "dddddddddd", "eeeeeeeeee",
|
||||||
"ffffffffff", "gggggggggg", "hhhhhhhhhh", "iiiiiiiiii", "jjjjjjjjjj"};
|
"ffffffffff", "gggggggggg", "hhhhhhhhhh", "iiiiiiiiii", "jjjjjjjjjj"};
|
||||||
unsigned int nkeys = 10;
|
unsigned int nkeys = 10;
|
||||||
|
FILE* mphf_fd = fopen("temp.mph", "w");
|
||||||
// Source of keys
|
// Source of keys
|
||||||
cmph_io_adapter_t *source = cmph_io_vector_adapter((char **)vector, nkeys);
|
cmph_io_adapter_t *source = cmph_io_vector_adapter((char **)vector, nkeys);
|
||||||
|
|
||||||
//Create minimal perfect hash function using the default (chm) algorithm.
|
//Create minimal perfect hash function using the default (chm) algorithm.
|
||||||
cmph_config_t *config = cmph_config_new(source);
|
cmph_config_t *config = cmph_config_new(source);
|
||||||
|
cmph_config_set_graphsize(config, 1.0); // this is not required, just to get a smaller function
|
||||||
|
cmph_config_set_algo(config, CMPH_BRZ);
|
||||||
|
cmph_config_set_mphf_fd(config, mphf_fd);
|
||||||
cmph_t *hash = cmph_new(config);
|
cmph_t *hash = cmph_new(config);
|
||||||
cmph_config_destroy(config);
|
cmph_config_destroy(config);
|
||||||
|
cmph_dump(hash, mphf_fd);
|
||||||
|
cmph_destroy(hash);
|
||||||
|
fclose(mphf_fd);
|
||||||
|
|
||||||
//Find key
|
//Find key
|
||||||
const char *key = "jjjjjjjjjj";
|
mphf_fd = fopen("temp.mph", "r");
|
||||||
unsigned int id = cmph_search(hash, key, strlen(key));
|
hash = cmph_load(mphf_fd);
|
||||||
fprintf(stderr, "Id:%u\n", id);
|
while (i < nkeys) {
|
||||||
|
const char *key = vector[i];
|
||||||
|
unsigned int id = cmph_search(hash, key, strlen(key));
|
||||||
|
fprintf(stderr, "key:%s -- hash:%u\n", key, id);
|
||||||
|
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);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user