MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / add_pair

Method add_pair

graphs/directed_and_undirected_weighted_graph.py:271–287  ·  view source on GitHub ↗
(self, u, v, w=1)

Source from the content-addressed store, hash-verified

269 # adding the weight is optional
270 # handles repetition
271 def add_pair(self, u, v, w=1):
272 # check if the u exists
273 if self.graph.get(u):
274 # if there already is a edge
275 if self.graph[u].count([w, v]) == 0:
276 self.graph[u].append([w, v])
277 else:
278 # if u does not exist
279 self.graph[u] = [[w, v]]
280 # add the other way
281 if self.graph.get(v):
282 # if there already is a edge
283 if self.graph[v].count([w, u]) == 0:
284 self.graph[v].append([w, u])
285 else:
286 # if u does not exist
287 self.graph[v] = [[w, u]]
288
289 # handles if the input does not exist
290 def remove_pair(self, u, v):

Callers 1

fill_graph_randomlyMethod · 0.95

Calls 3

countMethod · 0.80
getMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected