This repository contains a generic hash table (hash map) implementation in C++, designed with a strong emphasis on data structures, collision handling, and correctness. The project is fully validated using Google Test and built with CMake, following a test-driven development approach.
The project implements a templated hash table with fixed capacity, supporting insertion, removal, lookup, and position tracking.
Collisions are handled using separate chaining, where each table index stores a linked list of elements.
The correctness of the implementation is ensured through an extensive suite of unit tests that validate behavior with and without collisions, including edge cases and exception handling.
- Generic hash table using C++ templates
- Fixed-capacity table defined at compile time
- Collision handling via separate chaining
- Accurate position tracking inside the table and collision lists
- Robust exception handling for invalid operations
- Comprehensive unit tests using Google Test
- Table initialization
- Insertions without collisions
- Insertions with collisions
- Removal without collisions
- Removal with collisions
- Lookup and containment checks
- Position reporting (table index and list position)
- Exception handling for non-existent elements
- Language: C++
- Build System: CMake
- Testing Framework: Google Test
- Paradigm: Object-Oriented Programming
- Concepts:
- Templates
- Hashing
- Collision resolution (separate chaining)
- Exception handling
- Unit testing
TabelaEspalhamentoAbstrata.h– Abstract hash table interfaceMinhaTabelaEspalhamento.h– Concrete hash table implementationPosicao.h– Structure representing table and list positionsexcecoes.h– Custom exception definitionsmain.cpp– Google Test test suite and test runnerCMakeLists.txt– Build configuration
This project is intended to be built and executed using WSL (Windows Subsystem for Linux).
- Windows with WSL installed
- Linux distribution (Ubuntu recommended)
- C++ compiler (g++)
- CMake
- Google Test
sudo apt update
sudo apt install build-essential cmake libgtest-devGoogle Test needs to be compiled after installation:
cd /usr/src/gtest
sudo cmake .
sudo make
sudo cp lib/*.a /usr/libFrom the project root directory:
mkdir build
cd build
cmake ..
make./HashTableTests(The executable name may vary depending on your CMakeLists.txt configuration.)
This project was developed to practice and demonstrate:
- Hash table implementation fundamentals
- Collision resolution strategies
- Template-based generic programming
- Precise data structure validation via unit tests
- CMake-based C++ project organization