00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00038 #ifndef CTRUMP_COMMON_INT_MAP_H
00039 #define CTRUMP_COMMON_INT_MAP_H
00040
00041 #include "ctrump/common/dll.h"
00042
00043 #ifdef __cplusplus
00044 extern "C" {
00045 #endif
00046
00047 struct ctrump_mempool;
00048
00052 struct ctrump_intmap_bucket {
00053 struct ctrump_intmap_bucket *chain;
00054 unsigned int key;
00055 void *val;
00056 };
00057
00061 struct ctrump_intmap {
00062 unsigned int size;
00063 struct ctrump_mempool *pool;
00064 struct ctrump_intmap_bucket **buckets;
00065 };
00066
00072 CTRUMP_EXTDEF void ctrump_intmap_init(struct ctrump_intmap *map, int size);
00073
00082 CTRUMP_EXTDEF void ctrump_intmap_init_pool(struct ctrump_intmap *map, int size,
00083 struct ctrump_mempool *pool);
00084
00088 CTRUMP_EXTDEF void ctrump_intmap_free(struct ctrump_intmap *map);
00089
00093 #define ctrump_intmap_resize(d,s) ctrump_intmap_resize_pool(d,s,NULL);
00094
00105 CTRUMP_EXTDEF void ctrump_intmap_resize_pool(struct ctrump_intmap *dest,
00106 const struct ctrump_intmap *src,
00107 struct ctrump_mempool *pool);
00108
00118 CTRUMP_EXTDEF struct ctrump_intmap_bucket *
00119 ctrump_intmap_lookup_add(struct ctrump_intmap *map,
00120 int *is_found,
00121 unsigned int key);
00122
00131 CTRUMP_EXTDEF void *
00132 ctrump_intmap_lookup(struct ctrump_intmap *map,
00133 int *found,
00134 unsigned int key);
00135
00144 CTRUMP_EXTDEF struct ctrump_intmap_bucket *
00145 ctrump_intmap_lookup_bucket(struct ctrump_intmap *map,
00146 int *found,
00147 unsigned int key);
00148
00149
00150 #define MUL15(x) ((((unsigned int)(x))*3U)/2U)
00151
00168 struct ctrump_intmap_iterator {
00169 int buckets_index;
00170 struct ctrump_intmap_bucket *next;
00171 };
00172
00178 CTRUMP_EXTDEF void ctrump_intmap_iterator_begin(struct ctrump_intmap_iterator *i,
00179 struct ctrump_intmap *map);
00180
00188 CTRUMP_EXTDEF int ctrump_intmap_iterator_next(struct ctrump_intmap_bucket **ret,
00189 struct ctrump_intmap_iterator *i,
00190 struct ctrump_intmap *map);
00191
00195 CTRUMP_EXTDEF int ctrump_intmap_get_num_elem(struct ctrump_intmap *map);
00196
00197 #ifdef __cplusplus
00198 }
00199 #endif
00200
00201 #endif