MCPcopy Create free account
hub / github.com/subbarayudu-j/TheAlgorithms-Python / DoubleHash

Class DoubleHash

data_structures/hashing/double_hash.py:7–33  ·  view source on GitHub ↗

Hash Table example with open addressing and Double Hash

Source from the content-addressed store, hash-verified

5
6
7class DoubleHash(HashTable):
8 """
9 Hash Table example with open addressing and Double Hash
10 """
11 def __init__(self, *args, **kwargs):
12 super().__init__(*args, **kwargs)
13
14 def __hash_function_2(self, value, data):
15
16 next_prime_gt = next_prime(value % self.size_table) \
17 if not check_prime(value % self.size_table) else value % self.size_table #gt = bigger than
18 return next_prime_gt - (data % next_prime_gt)
19
20 def __hash_double_function(self, key, data, increment):
21 return (increment * self.__hash_function_2(key, data)) % self.size_table
22
23 def _colision_resolution(self, key, data=None):
24 i = 1
25 new_key = self.hash_function(data)
26
27 while self.values[new_key] is not None and self.values[new_key] != key:
28 new_key = self.__hash_double_function(key, data, i) if \
29 self.balanced_factor() >= self.lim_charge else None
30 if new_key is None: break
31 else: i += 1
32
33 return new_key

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected