pyhashmaps
is a fully annotated Python package which has several functional hashmap classes for educational purposes.
All classes support common operations on MutableMapping
type.
It has a class hierarchy of:
- Open Addressing:
- Linear Probing
- Quadratic Probing
- Double Hashing
- Separate Chaining:
- Using DynamicArray
- Using LinkedList
- Using Binary Search Tree
It's tested on Python 3.10 & 3.11.
If you have git
installed:
pip install git+https://github.com/amirsoroush/Python_Hashmaps.git
Otherwise:
pip install https://github.com/amirsoroush/Python_Hashmaps/tarball/main
It has the same interface as the built-in dict
class.
>>> from pyhashmaps import (
... LinearProbingHashMap,
... QuadraticProbingHashMap,
... DoubleHashingHashMap,
... DynamicArrayHashMap,
... LinkedListHashMap,
... BSTHashMap,
... )
>>>
>>> hashmap = LinearProbingHashMap()
>>> hashmap = LinearProbingHashMap[str, int]()
>>> hashmap["a"] = 10
>>> hashmap
LinearProbingHashMap({'a': 10})
>>> hashmap.update({"b": 20, "c": 30})
>>> len(hashmap)
3
>>> for k, v in hashmap.items():
... print(k, v)
...
c 30
a 10
b 20
>>> hashmap.clear()
>>>