Skip to content

Commit 80afe9e

Browse files
committed
Three Hundred - Eighteen Commit: Implement lprobe() function
1 parent a6cad98 commit 80afe9e

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

Section_11(Hash-Table)/(2)_hash-table-linear-probing.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,15 @@ def __init__(self):
1515
self.hashtable_size = 10
1616
self.hashtable = [0] * self.hashtable_size
1717

18+
# Hashing function
1819
def hashcode(self, key):
1920
return key % self.hashtable_size
21+
22+
# Function to compute next index to insert element if index already
23+
# has an element stored in the Hash Table
24+
def lprobe(self, element):
25+
i = self.hashcode(element)
26+
j = 0
27+
while self.hashtable[(i + j) % self.hashtable_size] != 0:
28+
j = j + 1
29+
return (i + j) % self.hashtable_size

0 commit comments

Comments
 (0)