src/hashing/hash_table.h
/**
 * Insert the given key into the hash table. The key cannot be NULL.
 * Returns 1 if the key is inserted, 0 if it already existed.
 */
Insert the given key into the hash table. The key cannot be NULL.
Returns 1 if the key is inserted, 0 if it already existed.
Insert the given key into the hash table . The key cannot be NULL . Returns 1 if the key is inserted 0 if it already existed .
inline char hash_table_insert(HashTable* hash_table, void* key) {
	assert(key != NULL);
	int i;
	size_t hash_value = HASH_POINTER(key) & (hash_table->bucket_count - 1);
	int chain_size = hash_table->chain_sizes[hash_value];
	for (i = 0; i < chain_size; ++i)
		if (hash_table->buckets[hash_value][i] == key)
			return 0;
	void** tmp = (void**) realloc(hash_table->buckets[hash_value], (chain_size + 1) * sizeof(void*));
	assert(tmp != NULL);
	hash_table->buckets[hash_value] = tmp;
	hash_table->buckets[hash_value][chain_size] = key;
	++hash_table->chain_sizes[hash_value];
	return 1;
}
inline char hash_table_insert ( HashTable * hash_table , void * key ) { assert ( key != NULL ) ; int i ; size_t hash_value = HASH_POINTER ( key ) & ( hash_table -> bucket_count - 1 ) ; int chain_size = hash_table -> chain_sizes [ hash_value ] ; for ( i = 0 ; i < chain_size ; ++ i ) if ( hash_table -> buckets [ hash_value ] [ i ] == key ) return 0 ; void * * tmp = ( void * * ) realloc ( hash_table -> buckets [ hash_value ] , ( chain_size + 1 ) * sizeof ( void * ) ) ; assert ( tmp != NULL ) ; hash_table -> buckets [ hash_value ] = tmp ; hash_table -> buckets [ hash_value ] [ chain_size ] = key ; ++ hash_table -> chain_sizes [ hash_value ] ; return 1 ; }
Insert the given key into the hash table.
Insert the given key into the hash table .
// check if the key already exists // insert the key