From a20002711aa60dd9290f0b411a8a22c056fd79d3 Mon Sep 17 00:00:00 2001 From: KDH Date: Sun, 15 Mar 2020 19:21:18 +0900 Subject: [PATCH 1/3] Fix rehashing function will not call insert_data function --- data_structures/hashing/hash_table.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/hashing/hash_table.py b/data_structures/hashing/hash_table.py index 988f2ba0dfbf..2dd346470cd0 100644 --- a/data_structures/hashing/hash_table.py +++ b/data_structures/hashing/hash_table.py @@ -62,7 +62,7 @@ def rehashing(self): self.size_table = next_prime(self.size_table, factor=2) self._keys.clear() self.values = [None] * self.size_table # hell's pointers D: don't DRY ;/ - map(self.insert_data, survivor_values) + list(map(self.insert_data, survivor_values)) def insert_data(self, data): key = self.hash_function(data) From 06e25caaefd53338919d7f5d85f9f77384bb1dc9 Mon Sep 17 00:00:00 2001 From: KDH Date: Sun, 15 Mar 2020 20:09:26 +0900 Subject: [PATCH 2/3] Fix typo --- data_structures/hashing/double_hash.py | 2 +- data_structures/hashing/hash_table_with_linked_list.py | 4 ++-- data_structures/hashing/quadratic_probing.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/data_structures/hashing/double_hash.py b/data_structures/hashing/double_hash.py index 6c3699cc9950..ce4454db0bef 100644 --- a/data_structures/hashing/double_hash.py +++ b/data_structures/hashing/double_hash.py @@ -24,7 +24,7 @@ def __hash_function_2(self, value, data): def __hash_double_function(self, key, data, increment): return (increment * self.__hash_function_2(key, data)) % self.size_table - def _colision_resolution(self, key, data=None): + def _collision_resolution(self, key, data=None): i = 1 new_key = self.hash_function(data) diff --git a/data_structures/hashing/hash_table_with_linked_list.py b/data_structures/hashing/hash_table_with_linked_list.py index 236985b69ac6..48d93bbc5cff 100644 --- a/data_structures/hashing/hash_table_with_linked_list.py +++ b/data_structures/hashing/hash_table_with_linked_list.py @@ -18,9 +18,9 @@ def balanced_factor(self): * self.charge_factor ) - def _colision_resolution(self, key, data=None): + def _collision_resolution(self, key, data=None): if not ( len(self.values[key]) == self.charge_factor and self.values.count(None) == 0 ): return key - return super()._colision_resolution(key, data) + return super()._collision_resolution(key, data) diff --git a/data_structures/hashing/quadratic_probing.py b/data_structures/hashing/quadratic_probing.py index ac966e1cd67e..0dd84a5d987c 100644 --- a/data_structures/hashing/quadratic_probing.py +++ b/data_structures/hashing/quadratic_probing.py @@ -11,7 +11,7 @@ class QuadraticProbing(HashTable): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) - def _colision_resolution(self, key, data=None): + def _collision_resolution(self, key, data=None): i = 1 new_key = self.hash_function(key + i * i) From 8833c1265a10a9f06a3600c273da5fd9ebffc772 Mon Sep 17 00:00:00 2001 From: KDH Date: Mon, 16 Mar 2020 18:46:56 +0900 Subject: [PATCH 3/3] Update loop syntax instead of allocating a list Co-Authored-By: Christian Clauss --- data_structures/hashing/hash_table.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/data_structures/hashing/hash_table.py b/data_structures/hashing/hash_table.py index 2dd346470cd0..3b39742f9d09 100644 --- a/data_structures/hashing/hash_table.py +++ b/data_structures/hashing/hash_table.py @@ -62,7 +62,8 @@ def rehashing(self): self.size_table = next_prime(self.size_table, factor=2) self._keys.clear() self.values = [None] * self.size_table # hell's pointers D: don't DRY ;/ - list(map(self.insert_data, survivor_values)) + for value in survivor_values: + self.insert_data(value) def insert_data(self, data): key = self.hash_function(data)