00001
00004 #ifndef _HCONTAINER_H
00005 #define _HCONTAINER_H
00006
00007 #include "hash_table.h"
00008 #include "jsoc.h"
00009
00010
00011 #define HCON_INITSIZE 2
00012
00014 struct HContainerElement_struct
00015 {
00016 char *key;
00017 void *val;
00018 };
00019
00020 typedef struct HContainerElement_struct HContainerElement_t;
00021
00023 struct HContainer_struct {
00024 int num_total;
00025 int datasize;
00026 int keysize;
00027 Hash_Table_t hash;
00028 void (*deep_free)(const void *value);
00029 void (*deep_copy)(const void *dst, const void *src);
00030 };
00031
00033 typedef struct HContainer_struct HContainer_t;
00034
00035 typedef struct HIterator_struct {
00036 HContainer_t *hc;
00037 int curr;
00038 HContainerElement_t **elems;
00039
00040 int nelems;
00041 int szelems;
00042 } HIterator_t;
00043
00044 struct Bundle_struct
00045 {
00046 void (*fmap)(const void *value, void *data);
00047 void *data;
00048 };
00049
00050 typedef struct Bundle_struct HContainerBundle_t;
00051
00052 void hcon_init(HContainer_t *hc, int datasize, int keysize,
00053 void (*deep_free)(const void *value),
00054 void (*deep_copy)(const void *dst, const void *src));
00055 void hcon_init_ext(HContainer_t *hc, unsigned int hashprime, int datasize, int keysize,
00056 void (*deep_free)(const void *value),
00057 void (*deep_copy)(const void *dst, const void *src));
00058 void *hcon_allocslot_lower(HContainer_t *hc, const char *key);
00059 void *hcon_allocslot(HContainer_t *hc, const char *key);
00060 void *hcon_lookup_lower(HContainer_t *hc, const char *key);
00061 void *hcon_lookup(HContainer_t *hc, const char *key);
00062 void *hcon_lookup_ext(HContainer_t *hc, const char *keyin, const char **keyout);
00063 void *hcon_getn(HContainer_t *hcon, unsigned int n);
00064 int hcon_member_lower(HContainer_t *hc, const char *key);
00065 int hcon_member(HContainer_t *hc, const char *key);
00066 void hcon_free(HContainer_t *hc);
00067 void hcon_remove(HContainer_t *hc, const char *key);
00068 void hcon_print(HContainer_t *hc);
00069 void hcon_printf(FILE *fp, HContainer_t *hc);
00070 void hcon_map(HContainer_t *hc, void (*fmap)(const void *value));
00071 void hcon_map_ext(HContainer_t *hc, void (*fmap)(const void *value, void *data), void *data);
00072 void hcon_copy(HContainer_t *dst, HContainer_t *src);
00073
00074 void hcon_stat(HContainer_t *hc);
00075
00076
00077 void hiter_new(HIterator_t *hit, HContainer_t *hc);
00078 void hiter_new_sort(HIterator_t *hit, HContainer_t *hc, int (*comp)(const void *, const void *));
00079 void hiter_free(HIterator_t *hit);
00080 void hiter_rewind(HIterator_t *hit);
00081
00082
00083
00084
00085
00086
00087 static inline int hcon_size(HContainer_t *hc)
00088 {
00089 return hc->num_total;
00090 }
00091
00092
00093
00094 static inline void *hiter_getcurrent(HIterator_t *hit)
00095 {
00096 if (hit->curr == -1)
00097 return NULL;
00098 else
00099 return (hit->elems[hit->curr])->val;
00100 }
00101
00102
00103 static inline void *hiter_getnext(HIterator_t *hit)
00104 {
00105 void *value = NULL;
00106
00107 if (hit->curr + 1 < hit->hc->num_total)
00108 {
00109 hit->curr++;
00110 value = (hit->elems[hit->curr])->val;
00111 }
00112
00113 return value;
00114 }
00115
00116 static inline void *hiter_extgetnext(HIterator_t *hit, const char **key)
00117 {
00118 void *value = NULL;
00119
00120 if (hit->curr + 1 < hit->hc->num_total)
00121 {
00122 hit->curr++;
00123 value = (hit->elems[hit->curr])->val;
00124 if (key)
00125 {
00126 *key = (hit->elems[hit->curr])->key;
00127 }
00128 }
00129
00130 return value;
00131
00132 }
00133
00134 static inline void *hcon_getval(HContainerElement_t *elem)
00135 {
00136 if (elem)
00137 {
00138 return elem->val;
00139 }
00140
00141 return NULL;
00142 }
00143
00144
00145 HContainer_t *hcon_create(int datasize,
00146 int keysize,
00147 void (*deep_free)(const void *value),
00148 void (*deep_copy)(const void *dst, const void *src),
00149 void **valArr,
00150 char **nameArr,
00151 int valArrSize);
00152 void hcon_destroy(HContainer_t **cont);
00153 int hcon_insert(HContainer_t *hcon, const char *key, const void *value);
00154 int hcon_insert_lower(HContainer_t *hcon, const char *key, const void *value);
00155 HIterator_t *hiter_create(HContainer_t *cont);
00156 void hiter_destroy(HIterator_t **iter);
00157
00158
00159 #endif