src/hashing/hash_table.h
/**
 * Remove the given key from the hash table. The key cannot be NULL.
 * Returns 1 if the key is removed, 0 if it did not exist.
 */
Remove the given key from the hash table. The key cannot be NULL.
Returns 1 if the key is removed, 0 if it did not exist.
Remove the given key from the hash table . The key cannot be NULL . Returns 1 if the key is removed 0 if it did not exist .
inline char hash_table_remove(HashTable* hash_table, void* key) {
	assert(key != NULL);
	if  (!hash_table_contains(hash_table, key))
		return 0;
	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)
			break;
	if (i == chain_size - 1 && hash_table->buckets[hash_value][i] != key)
		return 0;
	hash_table->buckets[hash_value][i] = NULL;
	/*
	int j;
	// shift the keys, overwrite the key to be removed
	for (j = i; j < chain_size - 1; ++j)
		hash_table->buckets[hash_value][j] = hash_table->buckets[hash_value][j + 1];
	// shrink the chain
	void** tmp = (void**) realloc(hash_table->buckets[hash_value], (chain_size - 1) * sizeof(void*));
	if(chain_size > 1)
		assert(tmp != NULL);
	hash_table->buckets[hash_value] = tmp;
	// decrement the chain size
	--hash_table->chain_sizes[hash_value];
	*/
	return 1;
}
inline char hash_table_remove ( HashTable * hash_table , void * key ) { assert ( key != NULL ) ; if ( ! hash_table_contains ( hash_table , key ) ) return 0 ; 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 ) break ; if ( i == chain_size - 1 && hash_table -> buckets [ hash_value ] [ i ] != key ) return 0 ; hash_table -> buckets [ hash_value ] [ i ] = NULL ; return 1 ; }
Remove the given key from the hash table.
Remove the given key from the hash table .
// return 0 if key is not in the hash // i is the index of the key to be removed. // mark it as a removed element. /*
	// i is the index of the key to be removed.
	int j;
	// shift the keys, overwrite the key to be removed
	for (j = i; j < chain_size - 1; ++j)
		hash_table->buckets[hash_value][j] = hash_table->buckets[hash_value][j + 1];

	// shrink the chain
	void** tmp = (void**) realloc(hash_table->buckets[hash_value], (chain_size - 1) * sizeof(void*));
	if(chain_size > 1)
		assert(tmp != NULL);
	hash_table->buckets[hash_value] = tmp;

	// decrement the chain size
	--hash_table->chain_sizes[hash_value];
	*/