<commit_before>/*
 * Copyright (c) [2014-2015] Novell, Inc.
 * Copyright (c) 2016 SUSE LLC
 *
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, contact Novell, Inc.
 *
 * To contact Novell about this file by physical or electronic mail, you may
 * find current contact information at www.novell.com.
 */


#ifndef STORAGE_ACTIONGRAPH_IMPL_H
#define STORAGE_ACTIONGRAPH_IMPL_H


#include <deque>
#include <boost/noncopyable.hpp>
#include <boost/graph/adjacency_list.hpp>

#include "storage/Devices/Device.h"
#include "storage/Actiongraph.h"


namespace storage
{
    using std::string;
    using std::vector;
    using std::deque;


    class Devicegraph;
    class Storage;
    class CommitCallbacks;


    namespace Action
    {
	class Base;
    }


    /**
     * Enum to allow filtering of actions in actions_with_sid().
     */
    enum ActionsFilter
    {
	ONLY_FIRST, ALL, ONLY_LAST
    };


    class Actiongraph::Impl : private boost::noncopyable
    {

    private:

	typedef boost::adjacency_list<boost::vecS, boost::listS, boost::bidirectionalS,
				      std::shared_ptr<Action::Base>> graph_t;

    public:

	typedef graph_t::vertex_descriptor vertex_descriptor;
	typedef graph_t::edge_descriptor edge_descriptor;

	typedef graph_t::vertex_iterator vertex_iterator;
	typedef graph_t::edge_iterator edge_iterator;

	typedef graph_t::adjacency_iterator adjacency_iterator;
	typedef graph_t::inv_adjacency_iterator inv_adjacency_iterator;

	typedef graph_t::vertices_size_type vertices_size_type;

	Impl(const Storage& storage, const Devicegraph* lhs, const Devicegraph* rhs);

	const Storage& get_storage() const { return storage; }

	const Devicegraph* get_devicegraph(Side side) const { return side == LHS ? lhs : rhs; }

	bool empty() const;

	size_t num_actions() const;

	vertex_descriptor add_vertex(Action::Base* action);

	edge_descriptor add_edge(vertex_descriptor a, vertex_descriptor b);

	/**
	 * Adds several actions (with their corresponding vertex_descriptors) to
	 * the graph, linking each other with edges (dependencies) in the given
	 * order.
	 */
	void add_chain(const vector<Action::Base*>& actions);

	/**
	 * Adds several edges (dependencies) to the graph, linking the actions
	 * in the given order.
	 */
	void add_chain(const vector<vertex_descriptor>& actions);

	/**
	 * Adds several edges (dependencies) to the graph, linking groups of
	 * actions in the given order. Thus, every action from the first vector
	 * will have an edge to every action from the second vector and so on.
	 */<commit_msg>Added note about add_chain cost<commit_after>/*
 * Copyright (c) [2014-2015] Novell, Inc.
 * Copyright (c) 2016 SUSE LLC
 *
 * All Rights Reserved.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2 of the GNU General Public License as published
 * by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, contact Novell, Inc.
 *
 * To contact Novell about this file by physical or electronic mail, you may
 * find current contact information at www.novell.com.
 */


#ifndef STORAGE_ACTIONGRAPH_IMPL_H
#define STORAGE_ACTIONGRAPH_IMPL_H


#include <deque>
#include <boost/noncopyable.hpp>
#include <boost/graph/adjacency_list.hpp>

#include "storage/Devices/Device.h"
#include "storage/Actiongraph.h"


namespace storage
{
    using std::string;
    using std::vector;
    using std::deque;


    class Devicegraph;
    class Storage;
    class CommitCallbacks;


    namespace Action
    {
	class Base;
    }


    /**
     * Enum to allow filtering of actions in actions_with_sid().
     */
    enum ActionsFilter
    {
	ONLY_FIRST, ALL, ONLY_LAST
    };


    class Actiongraph::Impl : private boost::noncopyable
    {

    private:

	typedef boost::adjacency_list<boost::vecS, boost::listS, boost::bidirectionalS,
				      std::shared_ptr<Action::Base>> graph_t;

    public:

	typedef graph_t::vertex_descriptor vertex_descriptor;
	typedef graph_t::edge_descriptor edge_descriptor;

	typedef graph_t::vertex_iterator vertex_iterator;
	typedef graph_t::edge_iterator edge_iterator;

	typedef graph_t::adjacency_iterator adjacency_iterator;
	typedef graph_t::inv_adjacency_iterator inv_adjacency_iterator;

	typedef graph_t::vertices_size_type vertices_size_type;

	Impl(const Storage& storage, const Devicegraph* lhs, const Devicegraph* rhs);

	const Storage& get_storage() const { return storage; }

	const Devicegraph* get_devicegraph(Side side) const { return side == LHS ? lhs : rhs; }

	bool empty() const;

	size_t num_actions() const;

	vertex_descriptor add_vertex(Action::Base* action);

	edge_descriptor add_edge(vertex_descriptor a, vertex_descriptor b);

	/**
	 * Adds several actions (with their corresponding vertex_descriptors) to
	 * the graph, linking each other with edges (dependencies) in the given
	 * order.
	 */
	void add_chain(const vector<Action::Base*>& actions);

	/**
	 * Adds several edges (dependencies) to the graph, linking the actions
	 * in the given order.
	 */
	void add_chain(const vector<vertex_descriptor>& actions);

	/**
	 * Adds several edges (dependencies) to the graph, linking groups of
	 * actions in the given order. Thus, every action from the first vector
	 * will have an edge to every action from the second vector and so on.
	 *
	 * By definition, the cost of this function is O(n^3). Although
	 * creating edges is not an expensive operation, take that cost into
	 * account when creating edges massively.
	 */
{'fraction_non_alphanumeric': 0.08114520721290731, 'fraction_numerical': 0.004270800379626701, 'mean_word_length': 4.170073589533933, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3712175', 'n_tokens_mistral': 1938, 'n_tokens_neox': 1756, 'n_words': 666}