Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions datastructures/graphs/vertex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ def __init__(self, data: T, incoming_edges: Set[Edge], outgoing_edges: Set[Edge]
self.incoming_edges = incoming_edges
self.outgoing_edges = outgoing_edges
self.edges = self.incoming_edges.union(self.outgoing_edges)
self.adjacent_vertices: Dict[str, 'Vertex'] = {}
self.properties = properties

def __str__(self):
Expand Down Expand Up @@ -109,6 +110,9 @@ def add_adjacent_vertex(self, other: 'Vertex'):
Args:
other (Vertex): Vertex to add as a neighbor
"""
if not self.adjacent_vertices.get(other.id):
self.adjacent_vertices[other.id] = other
other.add_adjacent_vertex(self)

def __eq__(self, other: 'Vertex') -> bool:
return self.id == other.id