1 #ifndef __CMPH_H__
2 #define __CMPH_H__
3
4 #include <stdlib.h>
5 #include <stdio.h>
6
7 #ifdef __cplusplus
8 extern "C"
9 {
10 #endif
11
12 #include "cmph_types.h"
13
14 typedef struct __config_t cmph_config_t;
15 typedef struct __cmph_t cmph_t;
16
17 typedef struct
18 {
19 void *data;
20 cmph_uint32 nkeys;
21 int (*read)(void *, char **, cmph_uint32 *);
22 void (*dispose)(void *, char *, cmph_uint32);
23 void (*rewind)(void *);
24 } cmph_io_adapter_t;
25
26 /** Adapter pattern API **/
27 /* please call free() in the created adapters */
28 cmph_io_adapter_t *cmph_io_nlfile_adapter(FILE * keys_fd);
29 void cmph_io_nlfile_adapter_destroy(cmph_io_adapter_t * key_source);
30
31 cmph_io_adapter_t *cmph_io_nlnkfile_adapter(FILE * keys_fd, cmph_uint32 nkeys);
32 void cmph_io_nlnkfile_adapter_destroy(cmph_io_adapter_t * key_source);
33
34 cmph_io_adapter_t *cmph_io_vector_adapter(char ** vector, cmph_uint32 nkeys);
35 void cmph_io_vector_adapter_destroy(cmph_io_adapter_t * key_source);
36
37 cmph_io_adapter_t *cmph_io_byte_vector_adapter(cmph_uint8 ** vector, cmph_uint32 nkeys);
38 void cmph_io_byte_vector_adapter_destroy(cmph_io_adapter_t * key_source);
39
40 cmph_io_adapter_t *cmph_io_struct_vector_adapter(void * vector,
41 cmph_uint32 struct_size,
42 cmph_uint32 key_offset,
43 cmph_uint32 key_len,
44 cmph_uint32 nkeys);
45
46 void cmph_io_struct_vector_adapter_destroy(cmph_io_adapter_t * key_source);
47
48 /** Hash configuration API **/
49 cmph_config_t *cmph_config_new(cmph_io_adapter_t *key_source);
50 void cmph_config_set_hashfuncs(cmph_config_t *mph, CMPH_HASH *hashfuncs);
51 void cmph_config_set_verbosity(cmph_config_t *mph, cmph_uint32 verbosity);
52 void cmph_config_set_graphsize(cmph_config_t *mph, double c);
53 void cmph_config_set_algo(cmph_config_t *mph, CMPH_ALGO algo);
54 void cmph_config_set_tmp_dir(cmph_config_t *mph, cmph_uint8 *tmp_dir);
55 void cmph_config_set_mphf_fd(cmph_config_t *mph, FILE *mphf_fd);
56 void cmph_config_set_b(cmph_config_t *mph, cmph_uint32 b);
57 void cmph_config_set_keys_per_bin(cmph_config_t *mph, cmph_uint32 keys_per_bin);
58 void cmph_config_set_memory_availability(cmph_config_t *mph, cmph_uint32 memory_availability);
59 void cmph_config_destroy(cmph_config_t *mph);
60
61 /** Hash API **/
62 cmph_t *cmph_new(cmph_config_t *mph);
63
64 /** cmph_uint32 cmph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen);
65 * \brief Computes the mphf value.
66 * \param mphf pointer to the resulting function
67 * \param key is the key to be hashed
68 * \param keylen is the key legth in bytes
69 * \return The mphf value
70 */
71 cmph_uint32 cmph_search(cmph_t *mphf, const char *key, cmph_uint32 keylen);
72
73 cmph_uint32 cmph_size(cmph_t *mphf);
74 void cmph_destroy(cmph_t *mphf);
75
76 /** Hash serialization/deserialization */
77 int cmph_dump(cmph_t *mphf, FILE *f);
78 cmph_t *cmph_load(FILE *f);
79
80 /** \fn void cmph_pack(cmph_t *mphf, void *packed_mphf);
81 * \brief Support the ability to pack a perfect hash function into a preallocated contiguous memory space pointed by packed_mphf.
82 * \param mphf pointer to the resulting mphf
83 * \param packed_mphf pointer to the contiguous memory area used to store the
84 * \param resulting mphf. The size of packed_mphf must be at least cmph_packed_size()
85 */
86 void cmph_pack(cmph_t *mphf, void *packed_mphf);
87
88 /** \fn cmph_uint32 cmph_packed_size(cmph_t *mphf);
89 * \brief Return the amount of space needed to pack mphf.
90 * \param mphf pointer to a mphf
91 * \return the size of the packed function or zero for failures
92 */
93 cmph_uint32 cmph_packed_size(cmph_t *mphf);
94
95 /** cmph_uint32 cmph_search(void *packed_mphf, const char *key, cmph_uint32 keylen);
96 * \brief Use the packed mphf to do a search.
97 * \param packed_mphf pointer to the packed mphf
98 * \param key key to be hashed
99 * \param keylen key legth in bytes
100 * \return The mphf value
101 */
102 cmph_uint32 cmph_search_packed(void *packed_mphf, const char *key, cmph_uint32 keylen);
103
104 // TIMING functions. To use the macro CMPH_TIMING must be defined
105 #include "cmph_time.h"
106
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif