CHAINED HASHING IMPLEMENTATION

Project leader: doug

About this project

This project is chained hashing implementation that can be freely included into programs by including chainedhashing.h.

A default hash function is provided by hashlittle() taken from lookup3 by Bob Jenkins. Custom hash function can be used by editing the configuration directives in the header.

This code is freely available under the General Public License for use. If you've any comments or questions I'd be eager to take any constructive input.

I am well aware that there is a debate raging between using prime factor hash tables and hash tables based on factors that are powers of 2. I regard both as good solutions for the definition of hash table widths and recognise that each has it's own advantages and disadvantages over the other (some of which are discussed briefly here).

Download

This implementation is made up of two files. You might want to take the configuration section from the header file and place it in a separate file. It is included in the header file merely for compactness.

How to use it in your code

#include "chainedhashing.h"
 
int main() {
 
    HASHITEM * removed_item;
    // Create table
    HASHTABLE * hash_table = create_hash_table(10);
 
    // Add items to the table
    insert_item(hash_table, create_hash_item("de", "Germany"));
    insert_item(hash_table, create_hash_item("uk", "United Kingdom"));
    insert_item(hash_table, create_hash_item("us", "United States of America"));
 
    print_hash_table(hash_table, 0);
 
    // Get a specific value by it's key
    printf("'%s' holds value '%s'\n", "uk", (char *)get_item_data(hash_table, "uk"));
 
    // Remove an item from the table
    removed_item = remove_item(hash_table, "de");
    free(removed_item);
 
    print_hash_table(hash_table, 0);
 
    // Finally destroy the table and free up it's resources
    destroy_hash_table(hash_table);
 
}
Powered by Debian, Jack Daniels, Guinness, and excessive quantities of caffeine and sugar.