static void _wi_array_optimize(wi_array_t *array) { wi_uinteger_t items_count; items_count = WI_CLAMP(array->data_count, array->min_count, _WI_ARRAY_MAX_COUNT); array->items = wi_realloc(array->items, items_count * sizeof(_wi_array_item_t *)); array->items_count = items_count; }
static void _wi_set_resize(wi_set_t *set) { _wi_set_bucket_t **buckets, *bucket, *next_bucket; wi_uinteger_t i, index, capacity, buckets_count; capacity = wi_exp2m1(wi_log2(set->data_count) + 1); buckets_count = WI_CLAMP(capacity, set->min_count, _WI_SET_MAX_COUNT); buckets = wi_malloc(buckets_count * sizeof(_wi_set_bucket_t *)); for(i = 0; i < set->buckets_count; i++) { for(bucket = set->buckets[i]; bucket; bucket = next_bucket) { next_bucket = bucket->next; index = _WI_SET_HASH(set, bucket->data) % buckets_count; bucket->next = buckets[index]; buckets[index] = bucket; } } wi_free(set->buckets); set->buckets = buckets; set->buckets_count = buckets_count; }
static void _wi_dictionary_optimize(wi_dictionary_t *dictionary) { _wi_dictionary_bucket_t **buckets, *bucket, *next_bucket; wi_uinteger_t i, index, capacity, buckets_count; capacity = wi_exp2m1(wi_log2(dictionary->key_count) + 1); buckets_count = WI_CLAMP(capacity, dictionary->min_count, _WI_DICTIONARY_MAX_COUNT); buckets = wi_malloc(buckets_count * sizeof(_wi_dictionary_bucket_t *)); for(i = 0; i < dictionary->buckets_count; i++) { for(bucket = dictionary->buckets[i]; bucket; bucket = next_bucket) { next_bucket = bucket->next; index = _WI_DICTIONARY_KEY_HASH(dictionary, bucket->key) % buckets_count; bucket->next = buckets[index]; buckets[index] = bucket; } } wi_free(dictionary->buckets); dictionary->buckets = buckets; dictionary->buckets_count = buckets_count; }