This project implements two types of hash maps in Python:
- Separate Chaining Hash Map (hash_map_sc.py): Uses linked lists to handle collisions.
- Open Addressing Hash Map (hash_map_oa.py): Uses quadratic probing and tombstones for collision resolution.
- Custom dynamic array implementation (
DynamicArray) - Two hash functions:
hash_function_1,hash_function_2 - Separate chaining with singly linked lists (
LinkedList) - Open addressing with quadratic probing (
HashEntry) - Methods for insertion, deletion, resizing, and key/value retrieval
- Utility function
find_modeto find the mode(s) in a dynamic array
Each hash map file contains a HashMap class with the following methods:
put(key, value): Insert or update a key-value pairget(key): Retrieve the value for a keyremove(key): Remove a key-value paircontains_key(key): Check if a key existsresize_table(new_capacity): Resize the hash tableget_keys_and_values(): Get all key-value pairs as a dynamic arrayclear(): Remove all entriestable_load(): Get the current load factorempty_buckets(): Count empty buckets
See the bottom of hash_map_sc.py and hash_map_oa.py for example usage and test cases.
- Python 3.6+
- No external dependencies
a6_include.py: Shared data structures and hash functionshash_map_sc.py: Separate chaining hash map implementationhash_map_oa.py: Open addressing hash map implementationREADME.md: Project documentation
You can run either hash map file directly to execute the included test cases:
python hash_map_sc.py
python hash_map_oa.pyThis project is for educational purposes.