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