6 #define ID_TABLE_DEBUG 0 9 #if ID_TABLE_DEBUG == 0 19 return rb_id_serial_to_id(key);
25 return rb_id_to_serial(
id);
48 #define ITEM_GET_KEY(tbl, i) ((tbl)->items[i].key) 49 #define ITEM_KEY_ISSET(tbl, i) ((tbl)->items[i].key) 50 #define ITEM_COLLIDED(tbl, i) ((tbl)->items[i].collision) 51 #define ITEM_SET_COLLIDED(tbl, i) ((tbl)->items[i].collision = 1) 58 #define ITEM_GET_KEY(tbl, i) ((tbl)->items[i].key >> 1) 59 #define ITEM_KEY_ISSET(tbl, i) ((tbl)->items[i].key > 1) 60 #define ITEM_COLLIDED(tbl, i) ((tbl)->items[i].key & 1) 61 #define ITEM_SET_COLLIDED(tbl, i) ((tbl)->items[i].key |= 1) 79 return (capa + 1) << 2;
87 capa = round_capa(capa);
88 tbl->
capa = (int)capa;
98 return rb_id_table_init(tbl, (
int)capa);
119 return (
size_t)tbl->
num;
132 int mask = tbl->
capa - 1;
138 ix = (ix + d) & mask;
149 int mask = tbl->
capa - 1;
155 ix = (ix + d) & mask;
162 ITEM_SET_KEY(tbl, ix,
key);
174 ITEM_SET_KEY(tbl, ix, 0);
187 int new_cap = round_capa(tbl->
num + (tbl->
num >> 1));
191 if (new_cap < tbl->
capa) {
192 new_cap = round_capa(tbl->
used + (tbl->
used >> 1));
194 tmp_tbl.
capa = new_cap;
196 for (i = 0; i < tbl->
capa; i++) {
199 hash_table_raw_insert(&tmp_tbl, key, tbl->
items[i].
val);
208 #if ID_TABLE_DEBUG && 0 216 fprintf(stderr,
"tbl: %p (capa: %d, num: %d, used: %d)\n", tbl, tbl->
capa, tbl->
num, tbl->
used);
217 for (i=0; i<
capa; i++) {
219 fprintf(stderr,
" -> [%d] %s %d\n", i,
rb_id2name(key2id(keys[i])), (
int)keys[i]);
229 int index = hash_table_index(tbl, key);
243 const int index = hash_table_index(tbl,
key);
249 hash_table_extend(tbl);
250 hash_table_raw_insert(tbl,
key, val);
258 return rb_id_table_insert_key(tbl, id2key(
id), val);
265 int index = hash_table_index(tbl, key);
266 return hash_delete_index(tbl, index);
274 for (i=0; i<
capa; i++) {
281 hash_delete_index(tbl, i);
293 for (i=0; i<
capa; i++) {
298 hash_delete_index(tbl, i);
enum rb_id_table_iterator_result rb_id_table_foreach_values_func_t(VALUE val, void *data)
int rb_id_table_lookup(struct rb_id_table *tbl, ID id, VALUE *valp)
#define ITEM_COLLIDED(tbl, i)
#define ZALLOC_N(type, n)
void rb_id_table_free(struct rb_id_table *tbl)
void rb_id_table_clear(struct rb_id_table *tbl)
#define ITEM_GET_KEY(tbl, i)
#define MEMZERO(p, type, n)
#define ITEM_KEY_ISSET(tbl, i)
#define ITEM_SET_COLLIDED(tbl, i)
struct rb_id_table * rb_id_table_create(size_t capa)
int rb_id_table_insert(struct rb_id_table *tbl, ID id, VALUE val)
void rb_id_table_foreach_values(struct rb_id_table *tbl, rb_id_table_foreach_values_func_t *func, void *data)
int rb_id_table_delete(struct rb_id_table *tbl, ID id)
size_t rb_id_table_size(const struct rb_id_table *tbl)
const char * rb_id2name(ID)
enum rb_id_table_iterator_result rb_id_table_foreach_func_t(ID id, VALUE val, void *data)
rb_id_table_iterator_result
size_t rb_id_table_memsize(const struct rb_id_table *tbl)
void rb_id_table_foreach(struct rb_id_table *tbl, rb_id_table_foreach_func_t *func, void *data)