Skip to content

Add typing to data_structures/hashing/hash_table.py #7040

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Oct 12, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions data_structures/hashing/hash_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,18 @@ class HashTable:
Basic Hash Table example with open addressing and linear probing
"""

def __init__(self, size_table, charge_factor=None, lim_charge=None):
def __init__(
self,
size_table: int,
charge_factor: int | None = None,
lim_charge: float | None = None,
Comment on lines +13 to +14
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Python and mypy can figure this out and it is a suggestion to the caller to pass in an int and not pass in None.

Suggested change
charge_factor: int | None = None,
lim_charge: float | None = None,
charge_factor: int = None,
lim_charge: float = None,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

makes sense, but code legibility changes, since it's optional.

Copy link
Contributor Author

@saksham-chawla saksham-chawla Oct 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cclauss if you have a strong opinion, i can change - but personally this looks more legible is all. :)

) -> None:
self.size_table = size_table
self.values = [None] * self.size_table
self.lim_charge = 0.75 if lim_charge is None else lim_charge
self.charge_factor = 1 if charge_factor is None else charge_factor
self.__aux_list = []
self._keys = {}
self.__aux_list: list = []
self._keys: dict = {}

def keys(self):
return self._keys
Expand Down