7 #define S_ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
11 3, 7, 11, 17, 23, 29, 37, 47, 59, 71, 89, 107, 131,
12 163, 197, 239, 293, 353, 431, 521, 631, 761, 919,
13 1103, 1327, 1597, 1931, 2333, 2801, 3371, 4049, 4861,
14 5839, 7013, 8419, 10103, 12143, 14591, 17519, 21023,
15 25229, 30293, 36353, 43627, 52361, 62851, 75431, 90523,
16 108631, 130363, 156437, 187751, 225307, 270371, 324449,
17 389357, 467237, 560689, 672827, 807403, 968897, 1162687,
18 1395263, 1674319, 2009191, 2411033, 2893249, 3471899,
19 4166287, 4999559, 5999471, 7199369
27 return hashfn(ht,
k) % ht->size;
31 return ht->opt.dupkey ? ht->opt.dupkey(
k) : (
KEY_TYPE)
k;
35 return ht->opt.dupvalue ? ht->opt.dupvalue(
v) : (
VALUE_TYPE)
v;
39 return ht->opt.calcsizeK ? ht->opt.calcsizeK(
k) : 0;
43 return ht->opt.calcsizeV ? ht->opt.calcsizeV(
v) : 0;
66 if (key_len != kv->key_len) {
70 bool res =
key == kv->key;
71 if (!res && ht->opt.cmp) {
72 res = !ht->opt.cmp(
key, kv->key);
78 return (
HT_(Kv) *)((
char *)bt->arr +
i * ht->opt.elem_size);
82 return (
HT_(Kv) *)((
char *)kv + ht->opt.elem_size);
85 #define BUCKET_FOREACH(ht, bt, j, kv) \
87 for ((j) = 0, (kv) = (bt)->arr; (j) < (bt)->count; (j)++, (kv) = next_kv(ht, kv))
89 #define BUCKET_FOREACH_SAFE(ht, bt, j, count, kv) \
91 for ((j) = 0, (kv) = (bt)->arr, (count) = (ht)->count; \
93 (j) = (count) == (ht)->count ? j + 1 : j, (kv) = (count) == (ht)->count ? next_kv(ht, kv) : kv, (count) = (ht)->count)
111 ht->prime_idx = prime_idx;
112 ht->table =
calloc(ht->size,
sizeof(*ht->table));
120 if (ht->opt.elem_size == 0) {
121 ht->opt.elem_size =
sizeof(
HT_(Kv));
136 for (
i = 0;
i < ht->size;
i++) {
137 HT_(Bucket) *bt = &ht->table[
i];
141 if (ht->opt.freefn) {
161 ht2 = internal_ht_new(sz,
idx, &ht->opt);
168 for (
i = 0;
i < ht->size;
i++) {
169 HT_(Bucket) *bt = &ht->table[
i];
182 ht2->opt.freefn =
NULL;
207 HT_(Kv) *newkvarr =
realloc(bt->arr, (bt->count + 1) * ht->opt.elem_size);
215 return kv_at(ht, bt, bt->count - 1);
219 HT_(Kv) *kv_dst = reserve_kv(ht, kv->key, kv->key_len,
update);
224 memcpy(kv_dst, kv, ht->opt.elem_size);
237 kv_dst->key_len = key_len;
272 HT_(Bucket) *bt = &ht->table[
bucketfn(ht, old_key)];
279 if (!ht->opt.dupvalue) {
290 memmove(kv,
src, (bt->count - j - 1) * ht->opt.elem_size);
346 memmove(kv,
src, (bt->count - j - 1) * ht->opt.elem_size);
358 for (
i = 0;
i < ht->size; ++
i) {
359 HT_(Bucket) *bt = &ht->table[
i];
364 if (!
cb(user, kv->key, kv->value)) {
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len key
static ut32 next_idx(ut32 idx)
RZ_API void Ht_() free(HtName_(Ht) *ht)
static ut32 calcsize_val(HtName_(Ht) *ht, const VALUE_TYPE v)
static KEY_TYPE dupkey(HtName_(Ht) *ht, const KEY_TYPE k)
RZ_API bool Ht_() update(HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value)
static const ut32 ht_primes_sizes[]
static bool insert_update(HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value, bool update)
static ut32 compute_size(ut32 idx, ut32 sz)
RZ_API VALUE_TYPE Ht_() find(HtName_(Ht) *ht, const KEY_TYPE key, bool *found)
static VALUE_TYPE dupval(HtName_(Ht) *ht, const VALUE_TYPE v)
static bool is_kv_equal(HtName_(Ht) *ht, const KEY_TYPE key, const ut32 key_len, const HT_(Kv) *kv)
static void internal_ht_grow(HtName_(Ht) *ht)
RZ_API bool Ht_() insert(HtName_(Ht) *ht, const KEY_TYPE key, VALUE_TYPE value)
static void freefn(HtName_(Ht) *ht, HT_(Kv) *kv)
#define BUCKET_FOREACH(ht, bt, j, kv)
static ut32 hashfn(HtName_(Ht) *ht, const KEY_TYPE k)
static void check_growing(HtName_(Ht) *ht)
RZ_API bool Ht_() insert_kv(HtName_(Ht) *ht, HT_(Kv) *kv, bool update)
RZ_API bool Ht_() update_key(HtName_(Ht) *ht, const KEY_TYPE old_key, const KEY_TYPE new_key)
#define BUCKET_FOREACH_SAFE(ht, bt, j, count, kv)
static ut32 bucketfn(HtName_(Ht) *ht, const KEY_TYPE k)
static ut32 calcsize_key(HtName_(Ht) *ht, const KEY_TYPE k)
RZ_API const KEY_TYPE bool * found
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
void * realloc(void *ptr, size_t size)
void * calloc(size_t number, size_t size)
static SdbKv * next_kv(HtPP *ht, SdbKv *kv)