| | |
| | | from typing import Any, Callable |
| | | |
| | | |
| | | class Graph: |
| | | def __init__(self): |
| | | self._adjacent: dict[int, set] = {} |
| | |
| | | return self |
| | | pass |
| | | |
| | | def get_attribute(self, vertex): |
| | | def get_attribute(self, vertex: int): |
| | | if vertex in self._adjacent: |
| | | return self._vertex_attribute[vertex] |
| | | else: |
| | |
| | | def vertices(self): |
| | | return self._adjacent.keys() |
| | | |
| | | def for_each_vertices(self, action): |
| | | def for_each_vertices(self, action: Callable[[int], Any]): |
| | | for v in self.vertices(): |
| | | action(v) |
| | | |
| | | def adjacent_of(self, vertex): |
| | | def adjacent_of(self, vertex: int): |
| | | if vertex not in self._adjacent: |
| | | raise ValueError(f"Graph does not include vertex {vertex}") |
| | | return self._adjacent.get(vertex) |
| | | |
| | | def for_each_edges(self, action): |
| | | def for_each_edges(self, action: Callable[[int, int], Any]): |
| | | visited_edges: dict[int, set] = {} |
| | | for start in self.vertices(): |
| | | for end in self.adjacent_of(start): |
| | |
| | | adjacent.add(second) |
| | | action(start, end) |
| | | |
| | | def get_lecture_name(self, vertex): |
| | | def get_lecture_name(self, vertex: int): |
| | | pass |
| | | |
| | | def set_lecture_name(self, vertex, name): |
| | | def set_lecture_name(self, vertex: int, name: str): |
| | | pass |
| | | |
| | | def __repr__(self): |