CIS 2400 lc4 hash

/************************************************************************/
/* File Name : lc4_hash.c */
/* Purpose : This file contains the definitions for the hash table */
/* */
/* Author(s) : tjf */
/************************************************************************/

#include
#include
#include “lc4_hash.h”

* creates a new hash table with num_of_buckets requested
lc4_memory_segmented* create_hash_table (int num_of_buckets,
int (*hash_function)(void* table, void *key) )
// allocate a single hash table struct

// allocate memory for the buckets (head pointers)

// assign function pointer to call back hashing function

// return 0 for success, -1 for failure
return 0 ;

* adds a new entry to the table
int add_entry_to_tbl (lc4_memory_segmented* table,
unsigned short int address,
unsigned short int contents)
// apply hashing function to determine proper bucket #
// add to bucket’s linked list using linked list add_to_list() helper function
return 0 ;

* search for an address in the hash table
row_of_memory* search_tbl_by_address (lc4_memory_segmented* table,
unsigned short int address )
// apply hashing function to determine bucket # item must be located in
// invoked linked_lists helper function, search_by_address() to return return proper node
return NULL;

* prints the linked list in a particular bucket

void print_bucket (lc4_memory_segmented* table,
int bucket_number,
FILE* output_file )
// call the linked list helper function to print linked list

* print the entire table (all buckets)
void print_table (lc4_memory_segmented* table,
FILE* output_file )
// call the linked list helper function to print linked list to output file for each bucket

* delete the entire table and underlying linked lists

void delete_table (lc4_memory_segmented* table )
// call linked list delete_list() on each bucket in hash table
// then delete the table itself