MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / hash_function

Method hash_function

data_structures/hashing/hash_table.py:56–81  ·  view source on GitHub ↗

Generates hash for the given key value Examples: Creating HashTable with size 5 >>> ht = HashTable(5) >>> ht.hash_function(10) 0 >>> ht.hash_function(20) 0 >>> ht.hash_function(4) 4 >>> ht.hash_function(18)

(self, key)

Source from the content-addressed store, hash-verified

54 )
55
56 def hash_function(self, key):
57 """
58 Generates hash for the given key value
59
60 Examples:
61
62 Creating HashTable with size 5
63 >>> ht = HashTable(5)
64 >>> ht.hash_function(10)
65 0
66 >>> ht.hash_function(20)
67 0
68 >>> ht.hash_function(4)
69 4
70 >>> ht.hash_function(18)
71 3
72 >>> ht.hash_function(-18)
73 2
74 >>> ht.hash_function(18.5)
75 3.5
76 >>> ht.hash_function(0)
77 0
78 >>> ht.hash_function(-0)
79 0
80 """
81 return key % self.size_table
82
83 def _step_by_step(self, step_ord):
84 print(f"step {step_ord}")

Callers 4

_collision_resolutionMethod · 0.95
insert_dataMethod · 0.95
_collision_resolutionMethod · 0.80
_collision_resolutionMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected