<commit_before>/// XXX add licence
//

#ifndef _DEPENDENCE_GRAPH_H_
#define _DEPENDENCE_GRAPH_H_

#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cassert>

#include "DGUtil.h"

namespace dg {

template <typename DG, typename NodePtrT>
class DGNode;

template <typename Key, typename ValueType>
class DependenceGraph;

/// --------------------------------------------------------
//  -- DGNode
//     one node in DependenceGraph
/// --------------------------------------------------------
template <typename DG, typename NodePtrT>
class DGNode
{
public:
    // TODO when LLVM is enabled, use SmallPtrSet
    // else BDD ?
    typedef std::set<NodePtrT> ControlEdgesType;
    typedef std::set<NodePtrT> DependenceEdgesType;

    typedef typename ControlEdgesType::iterator control_iterator;
    typedef typename ControlEdgesType::const_iterator const_control_iterator;
    typedef typename DependenceEdgesType::iterator dependence_iterator;
    typedef typename DependenceEdgesType::const_iterator const_dependence_iterator;

#ifdef ENABLE_CFG
    typedef std::set<NodePtrT> CFGEdgesType;
    typedef typename CFGEdgesType::iterator cfg_iterator;
    typedef typename CFGEdgesType::const_iterator const_cfg_iterator;
#endif /* ENABLE_CFG */

    DGNode<DG, NodePtrT>():subgraph(NULL), parameters(NULL), dfs_run(0) {}

    bool addControlDependence(NodePtrT n)
    {
        bool ret1, ret2;

        ret1 = n->revControlDepEdges.insert(static_cast<NodePtrT>(this)).second;
        ret2 = controlDepEdges.insert(n).second;

        // we either have both edges or none
        assert(ret1 == ret2);

        DBG(CONTROL, "Added control edge [%p]->[%p]\n", this, n);

        return ret2;
    }

    bool addDataDependence(NodePtrT n)
    {
        bool ret1, ret2;

        ret1 = n->revDataDepEdges.insert(static_cast<NodePtrT>(this)).second;
        ret2 = dataDepEdges.insert(n).second;

        assert(ret1 == ret2);

        DBG(DEPENDENCE, "Added dependence edge [%p]->[%p]\n", this, n);

        return ret2;
    }

    unsigned int getDFSrun(void) const { return dfs_run; }
    unsigned int setDFSrun(unsigned int r) { dfs_run = r; }

    // control dependency edges iterators
    control_iterator control_begin(void) { return controlDepEdges.begin(); }
    const_control_iterator control_begin(void) const { return controlDepEdges.begin(); }
    control_iterator control_end(void) { return controlDepEdges.end(); }
    const_control_iterator control_end(void) const { return controlDepEdges.end(); }

    // reverse control dependency edges iterators
    control_iterator rev_control_begin(void) { return revControlDepEdges.begin(); }
    const_control_iterator rev_control_begin(void) const { return revControlDepEdges.begin(); }
    control_iterator rev_control_end(void) { return revControlDepEdges.end(); }
    const_control_iterator rev_control_end(void) const { return revControlDepEdges.end(); }

    // data dependency edges iterators
    dependence_iterator dependence_begin(void) { return dataDepEdges.begin(); }
    const_dependence_iterator dependence_begin(void) const { return dataDepEdges.begin(); }
    dependence_iterator dependence_end(void) { return dataDepEdges.end(); }
    const_dependence_iterator dependence_end(void) const { return dataDepEdges.end(); }

    // reverse data dependency edges iterators
    dependence_iterator rev_dependence_begin(void) { return revDataDepEdges.begin(); }
    const_dependence_iterator rev_dependence_begin(void) const { return revDataDepEdges.begin(); }
    dependence_iterator rev_dependence_end(void) { return revDataDepEdges.end(); }
    const_dependence_iterator rev_dependence_end(void) const { return revDataDepEdges.end(); }

#ifdef ENABLE_CFG
    void addSucc(NodePtrT s) { succs.insert(s); }

    cfg_iterator succ_begin(void) { return succs.begin(); }
    const_cfg_iterator succ_begin(void) const { return succs.begin(); }
    cfg_iterator succ_end(void) { return succs.end(); }
    const_cfg_iterator succ_end(void) const { return succs.end(); }
    unsigned int getSuccNum(void) const { return succs.size(); }
#endif /* ENABLE_CFG */

    DG *addSubgraph(DG *sub)
    {
        DG *old = subgraph;<commit_msg>dg: add setters for number of control/data edges<commit_after>/// XXX add licence
//

#ifndef _DEPENDENCE_GRAPH_H_
#define _DEPENDENCE_GRAPH_H_

#include <utility>
#include <set>
#include <queue>
#include <map>
#include <cassert>

#include "DGUtil.h"

namespace dg {

template <typename DG, typename NodePtrT>
class DGNode;

template <typename Key, typename ValueType>
class DependenceGraph;

/// --------------------------------------------------------
//  -- DGNode
//     one node in DependenceGraph
/// --------------------------------------------------------
template <typename DG, typename NodePtrT>
class DGNode
{
public:
    // TODO when LLVM is enabled, use SmallPtrSet
    // else BDD ?
    typedef std::set<NodePtrT> ControlEdgesType;
    typedef std::set<NodePtrT> DependenceEdgesType;

    typedef typename ControlEdgesType::iterator control_iterator;
    typedef typename ControlEdgesType::const_iterator const_control_iterator;
    typedef typename DependenceEdgesType::iterator dependence_iterator;
    typedef typename DependenceEdgesType::const_iterator const_dependence_iterator;

#ifdef ENABLE_CFG
    typedef std::set<NodePtrT> CFGEdgesType;
    typedef typename CFGEdgesType::iterator cfg_iterator;
    typedef typename CFGEdgesType::const_iterator const_cfg_iterator;
#endif /* ENABLE_CFG */

    DGNode<DG, NodePtrT>():subgraph(NULL), parameters(NULL), dfs_run(0) {}

    bool addControlDependence(NodePtrT n)
    {
        bool ret1, ret2;

        ret1 = n->revControlDepEdges.insert(static_cast<NodePtrT>(this)).second;
        ret2 = controlDepEdges.insert(n).second;

        // we either have both edges or none
        assert(ret1 == ret2);

        DBG(CONTROL, "Added control edge [%p]->[%p]\n", this, n);

        return ret2;
    }

    bool addDataDependence(NodePtrT n)
    {
        bool ret1, ret2;

        ret1 = n->revDataDepEdges.insert(static_cast<NodePtrT>(this)).second;
        ret2 = dataDepEdges.insert(n).second;

        assert(ret1 == ret2);

        DBG(DEPENDENCE, "Added dependence edge [%p]->[%p]\n", this, n);

        return ret2;
    }

    unsigned int getDFSrun(void) const { return dfs_run; }
    unsigned int setDFSrun(unsigned int r) { dfs_run = r; }

    // control dependency edges iterators
    control_iterator control_begin(void) { return controlDepEdges.begin(); }
    const_control_iterator control_begin(void) const { return controlDepEdges.begin(); }
    control_iterator control_end(void) { return controlDepEdges.end(); }
    const_control_iterator control_end(void) const { return controlDepEdges.end(); }

    // reverse control dependency edges iterators
    control_iterator rev_control_begin(void) { return revControlDepEdges.begin(); }
    const_control_iterator rev_control_begin(void) const { return revControlDepEdges.begin(); }
    control_iterator rev_control_end(void) { return revControlDepEdges.end(); }
    const_control_iterator rev_control_end(void) const { return revControlDepEdges.end(); }

    // data dependency edges iterators
    dependence_iterator dependence_begin(void) { return dataDepEdges.begin(); }
    const_dependence_iterator dependence_begin(void) const { return dataDepEdges.begin(); }
    dependence_iterator dependence_end(void) { return dataDepEdges.end(); }
    const_dependence_iterator dependence_end(void) const { return dataDepEdges.end(); }

    // reverse data dependency edges iterators
    dependence_iterator rev_dependence_begin(void) { return revDataDepEdges.begin(); }
    const_dependence_iterator rev_dependence_begin(void) const { return revDataDepEdges.begin(); }
    dependence_iterator rev_dependence_end(void) { return revDataDepEdges.end(); }
    const_dependence_iterator rev_dependence_end(void) const { return revDataDepEdges.end(); }

    unsigned int getControlDependenciesNum() const { return controlDepEdges.size(); }
    unsigned int getRevControlDependenciesNum() const { return revControlDepEdges.size(); }
    unsigned int getDataDependenciesNum() const { return dataDepEdges.size(); }
    unsigned int getRevDataDependenciesNum() const { return revDataDepEdges.size(); }

#ifdef ENABLE_CFG
    void addSucc(NodePtrT s) { succs.insert(s); }

    cfg_iterator succ_begin(void) { return succs.begin(); }
    const_cfg_iterator succ_begin(void) const { return succs.begin(); }
    cfg_iterator succ_end(void) { return succs.end(); }
    const_cfg_iterator succ_end(void) const { return succs.end(); }
    unsigned int getSuccNum(void) const { return succs.size(); }
#endif /* ENABLE_CFG */

    DG *addSubgraph(DG *sub)
    {
        DG *old = subgraph;
{'fraction_non_alphanumeric': 0.12482977757603268, 'fraction_numerical': 0.003404448479346346, 'mean_word_length': 3.768939393939394, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '1165200', 'n_tokens_mistral': 2700, 'n_tokens_neox': 2584, 'n_words': 608}