-
Notifications
You must be signed in to change notification settings - Fork 1
/
linked_list_hashtable_class.py
46 lines (27 loc) · 1.11 KB
/
linked_list_hashtable_class.py
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
class LinkedListHashTable:
def __init__(self, size) -> None:
self.items = []
for i in range(size):
self.items.append([])
def search(self, phone):
hashtable_index = phone % 800000
current_index_list = self.items[hashtable_index]
for probes_data in current_index_list:
if probes_data[0] == phone:
return probes_data
return False
def insert(self, data):
hashtable_index = data[0] % 800000
if self.search(data[0]):
raise Exception("Given number already exist!")
self.items[hashtable_index].append(data)
def delete(self, phone):
if not self.search(phone):
raise Exception("Error! Phone Number does not Exist in our database!")
hashtable_index = phone % 800000
inside_remove_index = 0
for i in range(len(self.items[hashtable_index])):
if self.items[hashtable_index][i][0] == phone:
inside_remove_index = i
break
self.items[hashtable_index].pop(inside_remove_index)