/* hash_sep.h */ #ifndef _HASH_SEP_H #define _HASH_SEP_H #define MIN_TABLE_SIZE 5 struct list_node; typedef struct list_node *position; struct hash_tbl; typedef struct hash_tbl *hash_table; typedef unsigned int hash_index; hash_index hash(const char *key, int table_size); hash_table initialize_table(int table_size); void destroy_table(hash_table h); position find(char *key, hash_table h); void insert(char *key, hash_table h); char *retrieve(position p); #endif
/* hash_sep.c */ #include "hash_sep.h" #include <string.h> #include <stdio.h> #include <stdlib.h> #include <error.h> struct list_node { char element[100]; position next; }; typedef position list; /* List *the_lists will be an array of lists, allocated later */ /* the lists use headers (for simplicity), */ /* though this wastes space */ struct hash_tbl { int table_size; list *the_lists; }; hash_index hash(const char *key, int table_size) { unsigned int hash_val = 0; while(*key != '