Skip to content
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

test: adding more tests to hash table algorithm #10400

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 15 additions & 1 deletion data_structures/hashing/hash_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
class HashTable:
"""
Basic Hash Table example with open addressing and linear probing
>>> ht = HashTable(10)
>>> ht.insert_data('foo')
>>> ht.insert_data('bar')
>>> len(ht.keys())
2

>>> 'foo' in ht.keys().values()
True
>>> ht.insert_data('foo') # Duplicates allowed
>>> ht.values.count('foo')
1

>>> ht.balanced_factor()
0.2
"""

def __init__(
Expand All @@ -29,7 +43,7 @@ def balanced_factor(self):
)

def hash_function(self, key):
return key % self.size_table
return hash(key) % self.size_table

def _step_by_step(self, step_ord):
print(f"step {step_ord}")
Expand Down