Example #1
0
void tommy_arrayof_done(tommy_arrayof* array)
{
	tommy_uint_t i;

	tommy_free(array->bucket[0]);
	for (i = TOMMY_ARRAYOF_BIT; i < array->bucket_bit; ++i) {
		unsigned char* segment = tommy_cast(unsigned char*, array->bucket[i]);
		tommy_free(segment + ((tommy_ptrdiff_t)1 << i) * array->element_size);
	}
}
Example #2
0
void tommy_hashlin_done(tommy_hashlin* hashlin)
{
	tommy_uint_t i;

	tommy_free(hashlin->bucket[0]);
	for (i = TOMMY_HASHLIN_BIT; i < hashlin->bucket_bit; ++i) {
		tommy_hashlin_node** segment = hashlin->bucket[i];
		tommy_free(&segment[((tommy_ptrdiff_t)1) << i]);
	}
}
Example #3
0
/**
 * Resize the bucket vector.
 */
void tommy_hashdyn_resize(tommy_hashdyn* hashdyn, unsigned new_bucket_bit)
{
	unsigned bucket_bit;
	unsigned bucket_max;
	unsigned new_bucket_max;
	unsigned new_bucket_mask;
	tommy_hashdyn_node** new_bucket;

	bucket_bit = hashdyn->bucket_bit;
	bucket_max = hashdyn->bucket_max;

	new_bucket_max = 1 << new_bucket_bit;
	new_bucket_mask = new_bucket_max - 1;
	new_bucket = tommy_cast(tommy_hashdyn_node**, tommy_malloc(new_bucket_max * sizeof(tommy_hashdyn_node*)));

	/* reinsert all the elements */
	if (new_bucket_bit > bucket_bit) {
		unsigned i;

		/* grow */
		for(i=0;i<bucket_max;++i) {
			tommy_hashdyn_node* j;

			/* setup the new two buckets */
			new_bucket[i] = 0;
			new_bucket[i + bucket_max] = 0;

			/* reinsert the bucket */
			j = hashdyn->bucket[i];
			while (j) {
				tommy_hashdyn_node* j_next = j->next;
				unsigned index = j->key & new_bucket_mask;
				if (new_bucket[index])
					tommy_list_insert_tail_not_empty(new_bucket[index], j);
				else
					tommy_list_insert_first(&new_bucket[index], j);
				j = j_next;
			}
		}
	} else {
		unsigned i;

		/* shrink */
		for(i=0;i<new_bucket_max;++i) {
			/* setup the new bucket with the lower bucket*/
			new_bucket[i] = hashdyn->bucket[i];

			/* concat the upper bucket */
			tommy_list_concat(&new_bucket[i], &hashdyn->bucket[i + new_bucket_max]);
		}
	}

	tommy_free(hashdyn->bucket);

	/* setup */
	hashdyn->bucket_bit = new_bucket_bit;
	hashdyn->bucket_max = new_bucket_max;
	hashdyn->bucket_mask = new_bucket_mask;
	hashdyn->bucket = new_bucket;
}
Example #4
0
void tommy_arrayblk_done(tommy_arrayblk* array)
{
	unsigned i;

	for(i=0;i<tommy_array_size(&array->block);++i)
		tommy_free(tommy_array_get(&array->block, i));

	tommy_array_done(&array->block);
}
Example #5
0
void tommy_hashlin_done(tommy_hashlin* hashlin)
{
	unsigned i;
	for(i=0;i<hashlin->bucket_mac;++i)
		tommy_free(hashlin->bucket[i]);
}
Example #6
0
void tommy_hashtable_done(tommy_hashtable* hashtable)
{
	tommy_free(hashtable->bucket);
}
Example #7
0
void tommy_hashdyn_done(tommy_hashdyn* hashdyn)
{
	tommy_free(hashdyn->bucket);
}