Skip to content

Commit eb45e14

Browse files
committed
Add graph methods: nodes, successors, has_node
1 parent 84225d1 commit eb45e14

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/graph/graph_representation.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ def __init__(self, *, users=None, edges=None, adjacency_list=None, connections=N
6161
self.connections: dict[int, set[int]] = (
6262
connections if connections else {}
6363
)
64+
self.graph = self
6465

6566
@classmethod
6667
def build_graph(cls, xml_file):
@@ -89,6 +90,15 @@ def get_user_connections(self, user_id):
8990
if self.user_exists(user_id):
9091
return self.connections[user_id]
9192

93+
def nodes(self):
94+
return list(self.adjacency_list.keys())
95+
96+
def successors(self, node):
97+
return self.adjacency_list.get(node, [])
98+
99+
def has_node(self, node):
100+
return node in self.adjacency_list
101+
92102
@staticmethod
93103
def parse_xml_to_graph(xml_file_path):
94104
# Split the text based on the user blocks

0 commit comments

Comments
 (0)