blob: e3dc97fac17557432a5db6a9154f5b89d7c9cc02 [file] [log] [blame]
Andrew de los Reyes81ebcd82010-03-09 15:56:18 -08001// Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Alex Vakulenko072359c2014-07-18 11:41:07 -07005#ifndef UPDATE_ENGINE_PAYLOAD_GENERATOR_TARJAN_H_
6#define UPDATE_ENGINE_PAYLOAD_GENERATOR_TARJAN_H_
Andrew de los Reyes81ebcd82010-03-09 15:56:18 -08007
Alex Vakulenko072359c2014-07-18 11:41:07 -07008// This is an implementation of Tarjan's algorithm which finds all
Andrew de los Reyes81ebcd82010-03-09 15:56:18 -08009// Strongly Connected Components in a graph.
10
11// Note: a true Tarjan algorithm would find all strongly connected components
12// in the graph. This implementation will only find the strongly connected
13// component containing the vertex passed in.
14
15#include <vector>
Alex Deymo161c4a12014-05-16 15:56:21 -070016
17#include "update_engine/payload_generator/graph_types.h"
Andrew de los Reyes81ebcd82010-03-09 15:56:18 -080018
19namespace chromeos_update_engine {
20
21class TarjanAlgorithm {
22 public:
23 TarjanAlgorithm() : index_(0), required_vertex_(0) {}
24
25 // 'out' is set to the result if there is one, otherwise it's untouched.
26 void Execute(Vertex::Index vertex,
27 Graph* graph,
28 std::vector<Vertex::Index>* out);
29 private:
30 void Tarjan(Vertex::Index vertex, Graph* graph);
31
32 Vertex::Index index_;
33 Vertex::Index required_vertex_;
34 std::vector<Vertex::Index> stack_;
Ben Chanf9cb98c2014-09-21 18:31:30 -070035 std::vector<std::vector<Vertex::Index>> components_;
Andrew de los Reyes81ebcd82010-03-09 15:56:18 -080036};
37
38} // namespace chromeos_update_engine
39
Alex Vakulenko072359c2014-07-18 11:41:07 -070040#endif // UPDATE_ENGINE_PAYLOAD_GENERATOR_TARJAN_H_