hashtbl


Namehashtbl JSON
Version 1.0.5 PyPI version JSON
download
home_pagehttps://pypi.org/project/hashtbl/
SummarySophisticate Hash Table
upload_time2024-10-29 16:05:33
maintainerNone
docs_urlNone
authorkhiat Mohammed Abderrezzak
requires_python>=3.6
licenseMIT
keywords hash table
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # hashtbl


[![PyPI version](https://badge.fury.io/py/hashtbl.svg)](https://badge.fury.io/py/hashtbl)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)


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:


```bash
pip install hashtbl
```


## Usage 


```python
from hashtbl import hashMap


x = hashMap(
    [
        ["key1", "value1"],
        ["key2", "value2"],
        ["key3", "value3"],
    ]
)


print(x)
```


### Output


```bash
{"key1": "value1", "key2": "value2", "key3": "value3"}
```


#### You Can Show All Details


```python
from hashtbl import hashMap


x = hashMap(
    [
        ["key1", "value1"],
        ["key2", "value2"],
        ["key3", "value3"],
    ],
    detail=True,
)


print(x)
```


### Output


```bash
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).


```python
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


```bash
[('algorithm', 'algo')] -> [('logarithm', 'log')] -> None (NULL)
```


#### You Can See It With All Details


```python
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


```bash
╒═══════════════════════╤═════════════════════════╤══════════════════════╤══════════════════════╕
│ 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](https://opensource.org/licenses/MIT) for more details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/hashtbl/",
    "name": "hashtbl",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": null,
    "keywords": "hash table",
    "author": "khiat Mohammed Abderrezzak",
    "author_email": "khiat.dev@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/2e/bd/d55fde7ccd61ecf10788868abfb5be4beb323c200a441338354e8b84e57a/hashtbl-1.0.5.tar.gz",
    "platform": null,
    "description": "# hashtbl\n\n\n[![PyPI version](https://badge.fury.io/py/hashtbl.svg)](https://badge.fury.io/py/hashtbl)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n\nThis 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.\n\n\n## Installation\n\n\nYou can install `hashtbl` via pip:\n\n\n```bash\npip install hashtbl\n```\n\n\n## Usage \n\n\n```python\nfrom hashtbl import hashMap\n\n\nx = hashMap(\n    [\n        [\"key1\", \"value1\"],\n        [\"key2\", \"value2\"],\n        [\"key3\", \"value3\"],\n    ]\n)\n\n\nprint(x)\n```\n\n\n### Output\n\n\n```bash\n{\"key1\": \"value1\", \"key2\": \"value2\", \"key3\": \"value3\"}\n```\n\n\n#### You Can Show All Details\n\n\n```python\nfrom hashtbl import hashMap\n\n\nx = hashMap(\n    [\n        [\"key1\", \"value1\"],\n        [\"key2\", \"value2\"],\n        [\"key3\", \"value3\"],\n    ],\n    detail=True,\n)\n\n\nprint(x)\n```\n\n\n### Output\n\n\n```bash\nHash function :\n_____________\n\nf(x) = ord(x) % N (Hash table capacity)\n\nExample :\n_______\n\nN = 26\n\nf(\"ABC\") = ord(\"ABC\") % 26 = (ord('A') + ord('B') + ord('C')) % 26 = (65 + 66 + 67) % 26 = 198 % 26 = 16\n\nThe value associated with the key \"ABC\" will be placed at index 16 in the hash table (array) with a capacity of 26.\n\nNotes :\n_____\n\n- 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.\n\n- If a key is duplicated in the hash table, the last value associated with this key will be saved.\n\nHash Table :\n__________\n\n\u2552\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2555\n\u2502 Key    \u2502   Hash function Output (Index) \u2502 Value    \u2502\n\u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561\n\u2502 \"key1\" \u2502                             14 \u2502 \"value1\" \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 \"key2\" \u2502                             15 \u2502 \"value2\" \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 \"key3\" \u2502                             16 \u2502 \"value3\" \u2502\n\u2558\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255b\n```\n\n\n## Advanced Usage\n\n\n#### You Can See The Key/Value Pairs In The Linked List If There Is More Than One Key In One Index (Hash Function Output).\n\n\n```python\nfrom hashtbl import hashMap\n\n\nx = hashMap(\n    [\n        [\"algorithm\", \"algo\"],\n        [\"logarithm\", \"log\"],\n    ],\n    detail=False,\n)\n\n\n# 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).\nprint(x.get_linked_list(5))\n```\n\n\n### Output\n\n\n```bash\n[('algorithm', 'algo')] -> [('logarithm', 'log')] -> None (NULL)\n```\n\n\n#### You Can See It With All Details\n\n\n```python\nfrom hashtbl import hashMap\n\n\nx = hashMap(\n    [\n        [\"algorithm\", \"algo\"],\n        [\"logarithm\", \"log\"],\n    ],\n    detail=True,\n)\n\n\n# 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).\nprint(x.get_linked_list(5))\n```\n\n\n### Output\n\n\n```bash\n\u2552\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2564\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2555\n\u2502 Current Value         \u2502 Current Value @ddress   \u2502 Next Value           \u2502 Next Value @ddress   \u2502\n\u255e\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u256a\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2561\n\u2502 ('algorithm', 'algo') \u2502 0x7f527dd225d0          \u2502 ('logarithm', 'log') \u2502 0x7f527dd21d50       \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 ('logarithm', 'log')  \u2502 0x7f527dd21d50          \u2502 None (NULL)          \u2502 0x95bcc0 (nil/0x0)   \u2502\n\u251c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u253c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2524\n\u2502 None (NULL)           \u2502 0x95bcc0 (nil/0x0)      \u2502                      \u2502                      \u2502\n\u2558\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2567\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u255b\n```\n\n\n### Note\n\n\nYou can use all methods of the built-in hash table (dictionary) with this custom hash table.\n\n\n## License\n\n\nThis project is licensed under the MIT LICENSE - see the [LICENSE](https://opensource.org/licenses/MIT) for more details.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Sophisticate Hash Table",
    "version": "1.0.5",
    "project_urls": {
        "Homepage": "https://pypi.org/project/hashtbl/"
    },
    "split_keywords": [
        "hash",
        "table"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "223127022569ed50c08377ed321bcf69fb32698413cc3f62a063e1611a952b5d",
                "md5": "9dbcabb63183158a5d085cefe29ad824",
                "sha256": "23d4bbe4cab998d7986c617e1d115fc1a6f2094a30100d1a958a67dafac5a607"
            },
            "downloads": -1,
            "filename": "hashtbl-1.0.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9dbcabb63183158a5d085cefe29ad824",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7653,
            "upload_time": "2024-10-29T16:05:31",
            "upload_time_iso_8601": "2024-10-29T16:05:31.532553Z",
            "url": "https://files.pythonhosted.org/packages/22/31/27022569ed50c08377ed321bcf69fb32698413cc3f62a063e1611a952b5d/hashtbl-1.0.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2ebdd55fde7ccd61ecf10788868abfb5be4beb323c200a441338354e8b84e57a",
                "md5": "450b211befaf407df66412e45c9cf35a",
                "sha256": "96889ac6d6c5a0242e5f69388e8a0d4b11efcff245626531ae81d52e702a74db"
            },
            "downloads": -1,
            "filename": "hashtbl-1.0.5.tar.gz",
            "has_sig": false,
            "md5_digest": "450b211befaf407df66412e45c9cf35a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 7982,
            "upload_time": "2024-10-29T16:05:33",
            "upload_time_iso_8601": "2024-10-29T16:05:33.210156Z",
            "url": "https://files.pythonhosted.org/packages/2e/bd/d55fde7ccd61ecf10788868abfb5be4beb323c200a441338354e8b84e57a/hashtbl-1.0.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-29 16:05:33",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "hashtbl"
}
        
Elapsed time: 0.37066s