Main Page | Modules | Data Structures | Directories | File List | Data Fields

hmap.h

00001 /* 
00002  * Copyright (c) 2005-2007 by KoanLogic s.r.l. - All rights reserved.  
00003  */
00004 
00005 #ifndef _U_HMAP_H_
00006 #define _U_HMAP_H_
00007 
00008 #include <sys/types.h>
00009 #include <u/libu.h>
00010 
00011 #ifdef __cplusplus
00012 extern "C" {
00013 #endif
00014 
00016 typedef enum {
00017     U_HMAP_ERR_NONE = 0,
00018     U_HMAP_ERR_EXISTS,
00019     U_HMAP_ERR_FAIL
00020 } u_hmap_ret_t;
00021 
00023 typedef enum {
00024     U_HMAP_TYPE_CHAIN,      
00025     U_HMAP_TYPE_LINEAR      
00026 } u_hmap_type_t;
00027 
00029 typedef enum {
00030     U_HMAP_OPTS_OWNSDATA =          0x1,    
00031     U_HMAP_OPTS_NO_OVERWRITE =      0x2,    
00032     U_HMAP_OPTS_HASH_STRONG =       0x4     
00033 } u_hmap_options_t;
00034 
00036 typedef enum {
00037     U_HMAP_PCY_NONE = 1,    
00039     U_HMAP_PCY_FIFO,    
00040     U_HMAP_PCY_LRU,     
00041     U_HMAP_PCY_LFU      
00042 } u_hmap_pcy_type_t;
00043 
00044 typedef struct u_hmap_s u_hmap_t;     
00045 typedef struct u_hmap_pcy_s u_hmap_pcy_t;     
00046 typedef struct u_hmap_opts_s u_hmap_opts_t;
00047 typedef struct u_hmap_q_s u_hmap_q_t;
00048 typedef struct u_hmap_o_s u_hmap_o_t;     
00049 
00050 /* internal pre-declarations */
00051 struct u_hmap_o_s 
00052 {
00053     void *key,
00054          *val;
00055 
00056     LIST_ENTRY(u_hmap_o_s) next;
00057 
00058     u_hmap_q_t *pqe; 
00059 };
00060 
00062 struct u_hmap_opts_s {
00063 
00064     size_t size,            
00065            max;             
00068     u_hmap_type_t type;         
00070     u_hmap_pcy_type_t policy;   
00072     int options;            
00076     size_t (*f_hash)(void *key, size_t buckets);   
00078     int (*f_comp)(void *k1, void *k2);   
00080     void (*f_free)(u_hmap_o_t *obj);   
00082     u_string_t *(*f_str)(u_hmap_o_t *obj);   
00083 };
00084 
00085 
00086 /* u_hmap_* */
00087 const char *u_hmap_strerror (u_hmap_ret_t);
00088 
00089 /* u_hmap_t */
00090 int u_hmap_new (u_hmap_opts_t *opts, u_hmap_t **hmap);
00091 int u_hmap_put (u_hmap_t *hmap, u_hmap_o_t *obj, u_hmap_o_t **old);
00092 int u_hmap_get (u_hmap_t *hmap, void *key, u_hmap_o_t **obj);
00093 int u_hmap_del (u_hmap_t *hmap, void *key, u_hmap_o_t **obj);
00094 int u_hmap_copy (u_hmap_t *to, u_hmap_t *from);
00095 void u_hmap_free (u_hmap_t *hmap);
00096 int u_hmap_foreach (u_hmap_t *hmap, int f(void *val));
00097 int u_hmap_foreach_keyval (u_hmap_t *hmap, int f(void *key, void *val));
00098 
00099 /* u_hmap_o_t */
00100 u_hmap_o_t *u_hmap_o_new (void *key, void *val);
00101 void u_hmap_o_free (u_hmap_o_t *obj);
00102 
00103 /* u_hmap_opts_t */
00104 int u_hmap_opts_new (u_hmap_opts_t **opts);
00105 void u_hmap_opts_init (u_hmap_opts_t *opts);
00106 int u_hmap_opts_copy (u_hmap_opts_t *to, u_hmap_opts_t *from);
00107 void u_hmap_opts_free (u_hmap_opts_t *opts);
00108 
00109 /* testing */
00110 void u_hmap_dbg (u_hmap_t *hmap);
00111 void u_hmap_opts_dbg (u_hmap_opts_t *opts);
00112 void u_hmap_pcy_dbg (u_hmap_t *hmap);
00113 
00114 
00115 #ifdef __cplusplus
00116 }
00117 #endif
00118 
00119 #endif /* !_U_HMAP_H_ */

←Products
© 2005-2007 - KoanLogic S.r.l. - All rights reserved