hashtbl
This library was created to simplify the concept of a hash table and explain how it works in the background in a clear and simple way, especially for beginners in data structures.
Installation
You can install hashtbl via pip:
pip install hashtbl
Usage
from hashtbl import hashMap
x = hashMap(
[
["key1", "value1"],
["key2", "value2"],
["key3", "value3"],
]
)
print(x)
Output
{"key1": "value1", "key2": "value2", "key3": "value3"}
You Can Show All Details
from hashtbl import hashMap
x = hashMap(
[
["key1", "value1"],
["key2", "value2"],
["key3", "value3"],
],
detail=True,
)
print(x)
Output
Hash function :
_____________
f(x) = ord(x) % N (Hash table capacity)
Example :
_______
N = 26
f("ABC") = ord("ABC") % 26 = (ord('A') + ord('B') + ord('C')) % 26 = (65 + 66 + 67) % 26 = 198 % 26 = 16
The value associated with the key "ABC" will be placed at index 16 in the hash table (array) with a capacity of 26.
Notes :
_____
- If a key has the same index as an existing key in the hash table, it will be placed after it because, in a hash table, each index is a linked list.
- If a key is duplicated in the hash table, the last value associated with this key will be saved.
Hash Table :
__________
╒════════╤════════════════════════════════╤══════════╕
│ Key │ Hash function Output (Index) │ Value │
╞════════╪════════════════════════════════╪══════════╡
│ "key1" │ 14 │ "value1" │
├────────┼────────────────────────────────┼──────────┤
│ "key2" │ 15 │ "value2" │
├────────┼────────────────────────────────┼──────────┤
│ "key3" │ 16 │ "value3" │
╘════════╧════════════════════════════════╧══════════╛
Advanced Usage
You Can See The Key/Value Pairs In The Linked List If There Is More Than One Key In One Index (Hash Function Output).
from hashtbl import hashMap
x = hashMap(
[
["algorithm", "algo"],
["logarithm", "log"],
],
detail=False,
)
# When the keys are 'algorithm' and 'logarithm', 5 is the output index of the hash function. You can view this index and all other key indexes by printing with all details (detail=True).
print(x.get_linked_list(5))
Output
[('algorithm', 'algo')] -> [('logarithm', 'log')] -> None (NULL)
You Can See It With All Details
from hashtbl import hashMap
x = hashMap(
[
["algorithm", "algo"],
["logarithm", "log"],
],
detail=True,
)
# When the keys are 'algorithm' and 'logarithm', 5 is the output index of the hash function. You can view this index and all other key indexes by printing with all details (detail=True).
print(x.get_linked_list(5))
Output
╒═══════════════════════╤═════════════════════════╤══════════════════════╤══════════════════════╕
│ Current Value │ Current Value @ddress │ Next Value │ Next Value @ddress │
╞═══════════════════════╪═════════════════════════╪══════════════════════╪══════════════════════╡
│ ('algorithm', 'algo') │ 0x7f527dd225d0 │ ('logarithm', 'log') │ 0x7f527dd21d50 │
├───────────────────────┼─────────────────────────┼──────────────────────┼──────────────────────┤
│ ('logarithm', 'log') │ 0x7f527dd21d50 │ None (NULL) │ 0x95bcc0 (nil/0x0) │
├───────────────────────┼─────────────────────────┼──────────────────────┼──────────────────────┤
│ None (NULL) │ 0x95bcc0 (nil/0x0) │ │ │
╘═══════════════════════╧═════════════════════════╧══════════════════════╧══════════════════════╛
Note
You can use all methods of the built-in hash table (dictionary) with this custom hash table.
License
This project is licensed under the MIT LICENSE - see the LICENSE for more details.
Metadata
Release files for hashtbl 1.0.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| hashtbl-1.0.5.tar.gz | 8.0 kB | Without provenance | Details for hashtbl-1.0.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| hashtbl-1.0.5-py3-none-any.whl | Python 3 | none | any | Details for hashtbl-1.0.5-py3-none-any.whl |
Total release size: 15.6 kB
Release files / hashtbl-1.0.5.tar.gz
| Download URL | hashtbl-1.0.5.tar.gz |
|---|---|
| Size | 8.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
96889ac6d6c5a0242e5f69388e8a0d4b11efcff245626531ae81d52e702a74db
|
|
BLAKE2b-256 checksum How to use checksums |
2ebdd55fde7ccd61ecf10788868abfb5be4beb323c200a441338354e8b84e57a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.2
|
Release files / hashtbl-1.0.5-py3-none-any.whl
| Download URL | hashtbl-1.0.5-py3-none-any.whl |
|---|---|
| Size | 7.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
23d4bbe4cab998d7986c617e1d115fc1a6f2094a30100d1a958a67dafac5a607
|
|
BLAKE2b-256 checksum How to use checksums |
223127022569ed50c08377ed321bcf69fb32698413cc3f62a063e1611a952b5d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.1 CPython/3.11.2
|
Security for hashtbl 1.0.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.