HashTable
This simple package provides a custom implementation of a hash table in Python,
created by following this tutorial written by Bartosz Zaczyński.
The HashTable
class replicates many methods from Python dictionaries, including
HashTable.clear()
and HashTable.update()
.
Installation
This package is available in PyPI.
Use the package manager pip to install HashTable
.
python3 -m pip install hashtable-nicolerg
Alternatively, experiment with HashTable
in a Docker container.
Usage
from hashtable_nicolerg.hashtable import HashTable
hash_table = HashTable(capacity=10, load_factor_threshold=0.5)
hash_table["blue"] = "sea"
hash_table["list"] = [1,2,3]
len(hash_table)
hash_table.capacity
hash_table.load_factor
hash_table.keys
hash_table.values
hash_table.pairs
del hash_table["list"]
hash_table.update({"blue":"0000FF"})
hash_table["blue"]
hash_table.clear()
Motivation
Developing this package reinforced knowledge in the following areas:
- Python classes, including dunder methods
- Hash table implementation, including handling hash collisions
- Testing, including TDD, unit tests, and
pytest
- Developing Python packages
Dev notes
- Create the recommended directory structure and populate files
- Build the package in the same directory as
pyproject.toml
, which should create a dist/
directory
python3 -m build
- Use Twine to upload the package to PyPI
python3 -m pip install --upgrade twine
python3 -m twine upload dist/*
- Install your newly uploaded package
python3 -m pip install hashtable-nicolerg
- To update the package, increment the version in `pyproject.toml``, build, and upload
python3 -m build
python3 -m twine upload --skip-existing dist/*
- Install and test your new version
python3 -m pip install hashtable-nicolerg --upgrade