00001 00002 #ifndef NPS_HTAB32_H 00003 #define NPS_HTAB32_H 00004 #include <stdint.h> 00005 #include "../error/error.h" 00006 00007 /* An opaque pointer type is used. However, the library is also designed 00008 for #including the C file directly. */ 00009 typedef struct nps_htab_t nps_HTAB; 00010 00011 /* 00012 extern nps_HTAB nps_htab_new(int64_t sz); 00013 extern nps_HTAB nps_htab_new_w_free(int64_t sz, void (*free_key) (const void*), 00014 void (*free_value) (const void*)); 00015 00016 User should indicate the maximum number of elements that will be stored. The function will create additional space according to the load factor policy. 00017 00018 On deletion of the hash table, the hash table will attempt to delete all contents with free(). The usrer can override this behavior using nps_htab_new_w_free to construct the hash table. 00019 00020 */ 00021 extern nps_HTAB *nps_htab_new(int64_t sz); 00022 extern nps_HTAB *nps_htab_new_w_free(int64_t sz, void (*free_key) (void*), 00023 void (*free_value) (void*)); 00024 00025 00026 /* 00027 extern void nps_htab_del(nps_HTAB *o); 00028 deletes all contents as well, defaulting to free() unless nps_htab_new_w_free created this 00029 hash table. 00030 */ 00031 extern void nps_htab_del(nps_HTAB *o); 00032 00033 extern int64_t nps_htab_len(nps_HTAB *o); 00034 extern int64_t nps_htab_alloc_size(nps_HTAB *o); 00035 00036 /* 00037 extern void* nps_htab_get(nps_HTAB *o, const char const* key_string); 00038 returns NULL if not found */ 00039 extern void* nps_htab_get(nps_HTAB *o, const char const* key_string); 00040 00041 /* returns 0 on success. */ 00042 extern int nps_htab_set(nps_HTAB *o, nps_error_t *err, char *restrict key_string, void* value); 00043 00044 /* nps_htab_remove returns 1 if not found, 0 on success. */ 00045 extern int nps_htab_remove(nps_HTAB *o, const char const *restrict key_string); 00046 00047 #endif