src/hashing/dynamic_hash_table.c
/**
 * A dynamic hash table implementation for storing keys only, no associated values.
 * The allocated space is doubled once the load factor reaches 0.75.
 * Uses open addressing with linear probing.
 * Keys cannot be NULL.
 * Allocated space is not shrunk after a removal.
 */
A dynamic hash table implementation for storing keys only, no associated values.
The allocated space is doubled once the load factor reaches 0.75.
Uses open addressing with linear probing.
Keys cannot be NULL.
Allocated space is not shrunk after a removal.
A dynamic hash table implementation for storing keys only no associated values . The allocated space is doubled once the load factor reaches 0 . 75 . Uses open addressing with linear probing . Keys cannot be NULL . Allocated space is not shrunk after a removal .
void dynamic_hash_table_init(DynamicHashTable* hash_table, unsigned int size) {
	if (size < 8)
		size = 8;
	else
		size = roundup_pow2(size);
	hash_table->elements = (void**) calloc(size, sizeof(void*));
	assert(hash_table->elements != NULL);
	hash_table->end_indexes = (unsigned int*) calloc(size, sizeof(unsigned int));
	assert(hash_table->end_indexes != NULL);
	hash_table->size = size;
	hash_table->element_count = 0;
	int i;
	for (i = 0; i < hash_table->size; ++i)
		hash_table->end_indexes[i] = i;
	return;
}
void dynamic_hash_table_init ( DynamicHashTable * hash_table , unsigned int size ) { if ( size < 8 ) size = 8 ; else size = roundup_pow2 ( size ) ; hash_table -> elements = ( void * * ) calloc ( size , sizeof ( void * ) ) ; assert ( hash_table -> elements != NULL ) ; hash_table -> end_indexes = ( unsigned int * ) calloc ( size , sizeof ( unsigned int ) ) ; assert ( hash_table -> end_indexes != NULL ) ; hash_table -> size = size ; hash_table -> element_count = 0 ; int i ; for ( i = 0 ; i < hash_table -> size ; ++ i ) hash_table -> end_indexes [ i ] = i ; return ; }
A dynamic hash table implementation for storing keys only, no associated values.
A dynamic hash table implementation for storing keys only no associated values .
// each chain initially ends at its starting point