ionnich commited on
Commit
8741466
1 Parent(s): 35a6313

Chore: Misc

Browse files
data_processing/__pycache__/graph_distribution.cpython-310.pyc CHANGED
Binary files a/data_processing/__pycache__/graph_distribution.cpython-310.pyc and b/data_processing/__pycache__/graph_distribution.cpython-310.pyc differ
 
data_structures/__pycache__/hash_table.cpython-310.pyc CHANGED
Binary files a/data_structures/__pycache__/hash_table.cpython-310.pyc and b/data_structures/__pycache__/hash_table.cpython-310.pyc differ
 
data_structures/hash_table.py CHANGED
@@ -31,6 +31,9 @@ class hash_table:
31
  def __len__(self):
32
  return self.size
33
 
 
 
 
34
  def insert(self, key):
35
  hash_index = self.hash(key)
36
  if self.keys[hash_index] is not None:
@@ -46,23 +49,34 @@ class hash_table:
46
  self.values[hash_index] += 1
47
 
48
  def search(self, key):
49
- hash_index = self.hash(key)
50
- # return the value if the key is found
51
- if self.keys[hash_index] == key:
52
- return self.values[hash_index]
 
 
 
 
53
 
54
- return None
55
 
56
  def delete(self, key):
57
- hash_index = self.hash(key)
58
- # delete the key value pair if the key is found
59
- if self.keys[hash_index] == key:
60
- self.values[hash_index] = 0
61
- self.keys[hash_index] = None
 
 
 
 
 
 
 
 
 
62
 
63
  def handle_collision(self, hash_index, key):
64
- def linear_probing(key):
65
- return (key + 1) % self.size
66
 
67
  while self.keys[hash_index] is not None:
68
  hash_index = linear_probing(hash_index)
 
31
  def __len__(self):
32
  return self.size
33
 
34
+ def linear_probing(key):
35
+ return (key + 1) % self.size
36
+
37
  def insert(self, key):
38
  hash_index = self.hash(key)
39
  if self.keys[hash_index] is not None:
 
49
  self.values[hash_index] += 1
50
 
51
  def search(self, key):
52
+ # probe the table until the key is found
53
+ initial = self.hash(key)
54
+ while self.keys[initial] is not None:
55
+ if self.keys[initial] == key:
56
+ return self.values[initial]
57
+ initial = linear_probing(initial)
58
+ if initial > self.size:
59
+ return 0
60
 
61
+ return 0
62
 
63
  def delete(self, key):
64
+ # check if key exists in table
65
+ if self.search(key) == 0:
66
+ return
67
+
68
+ # delete the key
69
+ initial = self.hash(key)
70
+ while self.keys[initial] is not None:
71
+ if self.keys[initial] == key:
72
+ self.keys[initial] = None
73
+ self.values[initial] = 0
74
+ return
75
+ initial = linear_probing(initial)
76
+ if initial > self.size:
77
+ return
78
 
79
  def handle_collision(self, hash_index, key):
 
 
80
 
81
  while self.keys[hash_index] is not None:
82
  hash_index = linear_probing(hash_index)