00001
00002
00003
00004
00005 #ifndef _U_HMAP_H_
00006 #define _U_HMAP_H_
00007
00008 #include <sys/types.h>
00009 #include <u/str.h>
00010
00011 #ifdef __cplusplus
00012 extern "C" {
00013 #endif
00014
00016 typedef enum {
00017 U_HMAP_PCY_NONE = 1,
00019 U_HMAP_PCY_FIFO,
00020 U_HMAP_PCY_LRU,
00021 U_HMAP_PCY_LFU
00022 } u_hmap_pcy_t;
00023
00025 typedef struct u_hmap_opts_s {
00026
00027 size_t max_size;
00028 size_t max_elems;
00029 u_hmap_pcy_t policy;
00032 size_t (*f_hash)(const char *key, size_t buckets);
00034 int (*f_comp)(const char *k1, const char *k2);
00036 void (*f_free)(void *val);
00038 u_string_t *(*f_str)(void *val);
00039 } u_hmap_opts_t;
00040
00041
00042 typedef struct u_hmap_s u_hmap_t;
00043
00044
00045
00046 int u_hmap_new (u_hmap_opts_t *opts, u_hmap_t **hmap);
00047 int u_hmap_put (u_hmap_t *hmap, const char *key, void *val);
00048 int u_hmap_get (u_hmap_t *hmap, const char *key, void **val);
00049 int u_hmap_del (u_hmap_t *hmap, const char *key);
00050 int u_hmap_free (u_hmap_t *hmap);
00051 int u_hmap_foreach (u_hmap_t *hmap, int f(void *val));
00052
00053
00054 int u_hmap_opts_new (u_hmap_opts_t **opts);
00055
00056
00057 void u_hmap_dbg (u_hmap_t *hmap);
00058 void u_hmap_opts_dbg (u_hmap_opts_t *opts);
00059 void u_hmap_pcy_dbg (u_hmap_t *hmap);
00060
00061 #ifdef __cplusplus
00062 }
00063 #endif
00064
00065 #endif