MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / contains_edge

Method contains_edge

graphs/graph_adjacency_list.py:165–181  ·  view source on GitHub ↗

Returns True if the graph contains the edge from the source_vertex to the destination_vertex, False otherwise. If any given vertex doesn't exist, a ValueError will be thrown.

(self, source_vertex: T, destination_vertex: T)

Source from the content-addressed store, hash-verified

163 return vertex in self.adj_list
164
165 def contains_edge(self, source_vertex: T, destination_vertex: T) -> bool:
166 """
167 Returns True if the graph contains the edge from the source_vertex to the
168 destination_vertex, False otherwise. If any given vertex doesn't exist, a
169 ValueError will be thrown.
170 """
171 if not (
172 self.contains_vertex(source_vertex)
173 and self.contains_vertex(destination_vertex)
174 ):
175 msg = (
176 f"Incorrect input: Either {source_vertex} "
177 f"or {destination_vertex} does not exist."
178 )
179 raise ValueError(msg)
180
181 return destination_vertex in self.adj_list[source_vertex]
182
183 def clear_graph(self) -> None:
184 """

Calls 1

contains_vertexMethod · 0.95

Tested by 1