-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHashTable.py
More file actions
60 lines (53 loc) · 1.74 KB
/
HashTable.py
File metadata and controls
60 lines (53 loc) · 1.74 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# Author: Jingze Dai
# Email Address: [email protected] or [email protected]
# Github: https://github.com/daijingz
# Linkedin: https://www.linkedin.com/in/jingze-dai/
# Description: HashTable
class DirectedAddressTable:
def __init__(self, length: int):
"""! Initialize the program"""
if length < 0:
raise Exception()
self.__length = length
self.__body = []
i = 0
while i < length:
self.__body += [None]
def get_length(self):
"""! Get the length value of object"""
try:
return self.__length
except:
raise Exception()
def get_body(self):
"""! Get the body value of object"""
try:
return self.__body
except:
raise Exception()
def direct_address_search(self, index: int):
"""! Search direct address"""
try:
if index < 0 or index >= self.__length:
raise ValueError()
return self.get_body()[index]
except:
raise Exception()
def direct_address_insert(self, index: int, data):
"""! Insert direct address"""
try:
if index < 0 or index >= self.__length:
raise ValueError()
elif self.__body[index] is not None:
raise ValueError()
self.__body[index] = data
except:
raise Exception()
def direct_address_delete(self, index: int):
"""! Delete direct address"""
try:
if index < 0 or index >= self.__length:
raise ValueError()
self.__body[index] = None
except:
raise Exception()