@@ -74,7 +74,7 @@ static const double __ac_HASH_UPPER = 0.77;
74
74
void kh_destroy_##name(kh_##name##_t *h); \
75
75
void kh_clear_##name(kh_##name##_t *h); \
76
76
khint_t kh_get_##name(const kh_##name##_t *h, khkey_t key); \
77
- int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
77
+ void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets); \
78
78
khint_t kh_put_##name(kh_##name##_t *h, khkey_t key, int *ret); \
79
79
void kh_del_##name(kh_##name##_t *h, khint_t x);
80
80
@@ -116,7 +116,7 @@ static const double __ac_HASH_UPPER = 0.77;
116
116
return __ac_iseither(h->flags, i)? h->n_buckets : i; \
117
117
} else return 0; \
118
118
} \
119
- SCOPE int kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
119
+ SCOPE void kh_resize_##name(kh_##name##_t *h, khint_t new_n_buckets) \
120
120
{ /* This function uses 0.25*n_buckets bytes of working space instead of [sizeof(key_t+val_t)+.25]*n_buckets. */ \
121
121
khint32_t * new_flags = NULL ; \
122
122
khint_t j = 1 ; \
@@ -126,7 +126,6 @@ static const double __ac_HASH_UPPER = 0.77;
126
126
if (h -> size >= (khint_t )(new_n_buckets * __ac_HASH_UPPER + 0.5 )) j = 0 ; /* requested size is too small */ \
127
127
else { /* hash table size to be changed (shrink or expand); rehash */ \
128
128
ALLOC_ARRAY (new_flags , __ac_fsize (new_n_buckets )); \
129
- if (!new_flags ) return -1 ; \
130
129
memset (new_flags , 0xaa , __ac_fsize (new_n_buckets ) * sizeof (khint32_t )); \
131
130
if (h -> n_buckets < new_n_buckets ) { /* expand */ \
132
131
REALLOC_ARRAY (h -> keys , new_n_buckets ); \
@@ -173,18 +172,15 @@ static const double __ac_HASH_UPPER = 0.77;
173
172
h -> n_occupied = h -> size ; \
174
173
h -> upper_bound = (khint_t )(h -> n_buckets * __ac_HASH_UPPER + 0.5 ); \
175
174
} \
176
- return 0 ; \
177
175
} \
178
176
SCOPE khint_t kh_put_ ##name (kh_##name##_t *h, khkey_t key, int *ret) \
179
177
{ \
180
178
khint_t x; \
181
179
if (h->n_occupied >= h->upper_bound) { /* update the hash table */ \
182
180
if (h -> n_buckets > (h -> size <<1 )) { \
183
- if (kh_resize_ ##name (h, h->n_buckets - 1) < 0) { /* clear "deleted" elements */ \
184
- * ret = -1 ; return h -> n_buckets ; \
185
- } \
186
- } else if (kh_resize_ ##name (h, h->n_buckets + 1) < 0) { /* expand the hash table */ \
187
- * ret = -1 ; return h -> n_buckets ; \
181
+ kh_resize_ ##name (h, h->n_buckets - 1); /* clear "deleted" elements */ \
182
+ } else { \
183
+ kh_resize_ ##name (h, h->n_buckets + 1); /* expand the hash table */ \
188
184
} \
189
185
} /* TODO: to implement automatically shrinking; resize() already support shrinking */ \
190
186
{ \
0 commit comments