forked from Samiullah-Kalhoro/hacktoberfest_21
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTable.py
More file actions
45 lines (33 loc) · 781 Bytes
/
Copy pathHashTable.py
File metadata and controls
45 lines (33 loc) · 781 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
hashTable = [[], ] * 10
def checkPrime(n):
if(n == 1 or n == 0):
return 0
for i in range(2, n//2):
if(n%i == 0):
return 0
return 1
def getPrime(n):
if(n%2 == 0):
n = n+1
while not checkPrime(n):
n += 2
return n
def hashFunction(key):
capacity = getPrime(10)
return key%capacity
def insertData(key, data):
index = hashFunction(key)
hashTable[index] = [key, data]
def removeData(key):
index = hashFunction(key)
hashTable[index] = 0
insertData(100, "Facebook")
insertData(101, "Apple")
insertData(102, "Amazon")
insertData(103, "Netflix")
insertData(104, "Google")
insertData(105, "Microsoft")
insertData(106, "Tesla")
print(hashTable)
removeData(102)
print(hashTable)