code: def _topological_sort(self):
          sorted_graph = []
          node_map = self._graph.get_nodes()
          nodes = [NodeVisitor(node_map[node]) for node in node_map]
          def get_pointers_for_edge_nodes(visitor_decorated_node):
              edges = []
              edge_ids = visitor_decorated_node.get_node().get_edges()
              for node in nodes:
                  if node.get_id() in edge_ids:
                      edges.append(node)
              return edges
          for node in nodes:
              for edge in get_pointers_for_edge_nodes(node):
                  edge.increment()
          resolved = [node for node in nodes if node.get_weight() == 0]
          while resolved:
              node = resolved.pop()
              sorted_graph.append(node)
              for edge in get_pointers_for_edge_nodes(node):
                  edge.decrement()
                  if edge.get_weight() == 0:
                      resolved.append(edge)
          self._circular_dependencies = [
              node.get_node() for node in nodes if node.get_weight() > 0]
          self._sorted_nodes = list(reversed(
              [node.get_node() for node in sorted_graph]))