Skip to content

A Python implementation of a hash table data structure using the djb2 hashing algorithm. It includes methods for adding key-value pairs, inspecting the table, and iterating over items in the table. Additionally, it features a word counter

Notifications You must be signed in to change notification settings

Tim-Quattrochi/py-word-counter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

16 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hash Table Implementation in Python

Project Description

This project uses a custom hash table to count word frequencies in a book.

Table of Contents 📖

Prerequisites

  • Python 3.x
  • Good knowledge of hash tables and their operations.

Setup

  1. Clone the repository:

    git clone git@github.com:Tim-Quattrochi/py-word-counter.git
    
  2. Navigate to the project directory:

    cd py-word-counter
    

Usage

I recommend using a virtual environment to run this program. To create a virtual environment, run the following command:

Windows

python -m venv venv

To activate the virtual environment, run the following command:

venv\Scripts\activate

Run the app.py script to start the program:

python app.py

MacOS/Linux

python3 -m venv venv

To activate the virtual environment, run the following command:

source venv/bin/activate

Run the app.py script to start the program:

python3 app.py

Functionality

The program implements a hash table with chaining and uses it to count word frequencies in a book. The hash table supports the following operations:

  • insert(key, value): Inserts a key-value pair into the hash table.
  • lookup(key): Returns the value associated with the given key.
  • delete(key): Removes the key-value pair associated with the given key from the hash table.
  • __len__(): Returns the number of key-value pairs in the hash table.
  • resize(int): Resizes the hash table to the given size.
  • items(): Returns a list or generator of all key-value pairs in the hash table.

Tests

I am using the unittest module to test the hash table implementation. To run the tests, use the following command:

python3 -m unittest test_hash_table.py

References

Citation


Book used as dataset:

Gray, J. (1920). The other Miller girl. New York: Chas. Scribners Sons. Link


⬆️ Back to Top

About

A Python implementation of a hash table data structure using the djb2 hashing algorithm. It includes methods for adding key-value pairs, inspecting the table, and iterating over items in the table. Additionally, it features a word counter

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages