Skip to content

Commit 45524dd

Browse files
ehdgua01cclauss
andauthored
Fix rehashing function will not call insert_data function (TheAlgorithms#1803)
* Fix rehashing function will not call insert_data function * Fix typo * Update loop syntax instead of allocating a list Co-Authored-By: Christian Clauss <cclauss@me.com> Co-authored-by: Christian Clauss <cclauss@me.com>
1 parent ab3400b commit 45524dd

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

data_structures/hashing/double_hash.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __hash_function_2(self, value, data):
2424
def __hash_double_function(self, key, data, increment):
2525
return (increment * self.__hash_function_2(key, data)) % self.size_table
2626

27-
def _colision_resolution(self, key, data=None):
27+
def _collision_resolution(self, key, data=None):
2828
i = 1
2929
new_key = self.hash_function(data)
3030

data_structures/hashing/hash_table.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ def rehashing(self):
6262
self.size_table = next_prime(self.size_table, factor=2)
6363
self._keys.clear()
6464
self.values = [None] * self.size_table # hell's pointers D: don't DRY ;/
65-
map(self.insert_data, survivor_values)
65+
for value in survivor_values:
66+
self.insert_data(value)
6667

6768
def insert_data(self, data):
6869
key = self.hash_function(data)

data_structures/hashing/hash_table_with_linked_list.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ def balanced_factor(self):
1818
* self.charge_factor
1919
)
2020

21-
def _colision_resolution(self, key, data=None):
21+
def _collision_resolution(self, key, data=None):
2222
if not (
2323
len(self.values[key]) == self.charge_factor and self.values.count(None) == 0
2424
):
2525
return key
26-
return super()._colision_resolution(key, data)
26+
return super()._collision_resolution(key, data)

data_structures/hashing/quadratic_probing.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class QuadraticProbing(HashTable):
1111
def __init__(self, *args, **kwargs):
1212
super().__init__(*args, **kwargs)
1313

14-
def _colision_resolution(self, key, data=None):
14+
def _collision_resolution(self, key, data=None):
1515
i = 1
1616
new_key = self.hash_function(key + i * i)
1717

0 commit comments

Comments
 (0)