Skip to content

Commit 5fc8ae0

Browse files
update List-of-Lists
1 parent cc93082 commit 5fc8ae0

File tree

1 file changed

+9
-16
lines changed

1 file changed

+9
-16
lines changed

List-of-Lists-main/lol_graph.py

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -143,23 +143,16 @@ def size(self):
143143
return len(self._neighbors_list)
144144

145145
def get_edge_data(self, node1, node2, default=None):
146+
number = self._map_node_to_number[node1]
147+
idx = self._index_list[number]
148+
idx_end = self._index_list[number + 1]
149+
node1_neighbors = self._neighbors_list[idx: idx_end]
150+
node2_index = self.binary_search(node1_neighbors, self._map_node_to_number[node2])
151+
if node2_index == -1:
152+
return default
146153
if self.is_weighted():
147-
number = self._map_node_to_number[node1]
148-
idx = self._index_list[number]
149-
idx_end = self._index_list[number + 1]
150-
node1_neighbors = self._neighbors_list[idx: idx_end]
151-
node2_index = self.binary_search(node1_neighbors, self._map_node_to_number[node2])
152-
if node2_index != -1:
153-
# if self._map_node_to_number[node2] in node1_neighbors:
154-
# node2_index = node1_neighbors.index(self._map_node_to_number[node2])
155-
return {"weight": self._weights_list[idx + node2_index]}
156-
else:
157-
if default is not None:
158-
return default
159-
else:
160-
return {'weight': 0}
161-
else:
162-
return {'weight': 1}
154+
return {"weight": self._weights_list[idx + node2_index]}
155+
return {}
163156

164157
# input: csv file containing edges list, in the form of [[5,1],[2,3],[5,3],[4,5]]
165158
def convert_with_csv(self, files_name, header=True):

0 commit comments

Comments
 (0)