Skip to content

eseverett/CSE310_Project1

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CSE 310: Project 1 - Hash Function DIY Contest
Team Alias: Team Eric Everett
Member: Eric Everett

Functionality:
This program implements a chaining hash table with a custom hash function to categorize and store string tokens. After reading an input file with a specified number of slots and tokens, the program distributes the tokens into linked lists at each slot using the hash function.

main.cpp:
The main function reads the input, then creates a HashTable object with k slots. Each string token is inserted into the hash table using the insert method. After all tokens are inserted, the program outputs:

1. The contents of the first 5 slots, showing the tokens in each.
2. The length of each slot, representing how many tokens are stored in each.
3. The standard deviation of the slot lengths, which measures the uniformity of token distribution.

hash.h:
This file defines the HashTable class and a Node struct. The Node struct represents each element in a slot's linked list, containing a key (token), a value (same as the key), and a pointer to the next Node. The HashTable class manages the hash table with a pointer to an array of Node pointers, representing the slots, and a table_size variable for the number of slots. It also declares methods for hash.cpp.

hash.cpp:
This file implements the methods declared in hash.h. It includes:

1. A constructor that initializes the hash table with a given number of slots.
2. A destructor that cleans up memory by deleting all nodes in each slot.
3. A hash_function that calculates a hash value for a given string using bitwise operations and then takes the result modulo the number of slots.
4. An insert method that adds a new node to the beginning of the linked list in the appropriate slot.
5. A method to print the contents of the first 5 slots.
6. A method to print the length of each slot.
7. A method to calculate and print the standard deviation of the slot lengths.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published