<commit_before>#ifndef _SDD_HOM_LOCAL_HH_
#define _SDD_HOM_LOCAL_HH_

#include <iosfwd>

#include "sdd/dd/definition.hh"
#include "sdd/hom/context_fwd.hh"
#include "sdd/hom/definition_fwd.hh"
#include "sdd/hom/identity.hh"

namespace sdd { namespace hom {

/*-------------------------------------------------------------------------------------------*/

/// @cond INTERNAL_DOC

/// @brief Local homomorphism.
template <typename C>
class local
{
private:

  /// @brief The variable type.
  typedef typename C::Variable variable_type;

  /// @brief The hierarchical node where the nested homomorphism will be carried to.
  const variable_type variable_;

  /// @brief The nested homomorphism to apply in a nested level.
  const homomorphism<C> h_;

public:

  /// @brief Constructor.
  local(const variable_type& var, const homomorphism<C>& h)
    : variable_(var)
    , h_(h)
  {
  }

  /// @brief Local's evaluation implementation.
  struct evaluation
  {
    typedef SDD<C> result_type;

    SDD<C>
    operator()( const hierarchical_node<C>& n
              , context<C>& cxt, const variable_type& var, const homomorphism<C>& h
              , const SDD<C>&)
    const
    {
      sum_builder<C, SDD<C>> sum_operands(n.size());
      for (const auto& arc : n)
      {
        sum_operands.add(SDD<C>(var, h(cxt, arc.valuation()), arc.successor()));
      }
      return sdd::sum(cxt.sdd_context(), std::move(sum_operands));
    }

    template <typename T>
    SDD<C>
    operator()( const T&, context<C>&, const variable_type&, const homomorphism<C>&
              , const SDD<C> s)
    const
    {
      throw evaluation_error<C>(s);
    }
  };

  /// @brief Evaluation.
  SDD<C>
  operator()(context<C>& cxt, const SDD<C>& s)
  const
  {
    return apply_visitor(evaluation(), s->data(), cxt, variable_, h_, s);
  }

  /// @brief Skip variable predicate.
  bool
  skip(const variable_type& v)<commit_msg>Manage Top in Local.<commit_after>#ifndef _SDD_HOM_LOCAL_HH_
#define _SDD_HOM_LOCAL_HH_

#include <iosfwd>

#include "sdd/dd/definition.hh"
#include "sdd/hom/context_fwd.hh"
#include "sdd/hom/definition_fwd.hh"
#include "sdd/hom/identity.hh"

namespace sdd { namespace hom {

/*-------------------------------------------------------------------------------------------*/

/// @cond INTERNAL_DOC

/// @brief Local homomorphism.
template <typename C>
class local
{
private:

  /// @brief The variable type.
  typedef typename C::Variable variable_type;

  /// @brief The hierarchical node where the nested homomorphism will be carried to.
  const variable_type variable_;

  /// @brief The nested homomorphism to apply in a nested level.
  const homomorphism<C> h_;

public:

  /// @brief Constructor.
  local(const variable_type& var, const homomorphism<C>& h)
    : variable_(var)
    , h_(h)
  {
  }

  /// @brief Local's evaluation implementation.
  struct evaluation
  {
    typedef SDD<C> result_type;

    SDD<C>
    operator()( const hierarchical_node<C>& n
              , context<C>& cxt, const variable_type& var, const homomorphism<C>& h
              , const SDD<C>& s)
    const
    {
      sum_builder<C, SDD<C>> sum_operands(n.size());
      for (const auto& arc : n)
      {
        sum_operands.add(SDD<C>(var, h(cxt, arc.valuation()), arc.successor()));
      }

      try
      {
        return sdd::sum(cxt.sdd_context(), std::move(sum_operands));
      }
      catch (top<C>& t)
      {
        evaluation_error<C> e(s);
        e.add_top(t);
        throw e;
      }
    }

    template <typename T>
    SDD<C>
    operator()( const T&, context<C>&, const variable_type&, const homomorphism<C>&
              , const SDD<C> s)
    const
    {
      throw evaluation_error<C>(s);
    }
  };

  /// @brief Evaluation.
  SDD<C>
  operator()(context<C>& cxt, const SDD<C>& s)
  const
  {
    return apply_visitor(evaluation(), s->data(), cxt, variable_, h_, s);
  }

  /// @brief Skip variable predicate.
  bool
  skip(const variable_type& v)
{'fraction_non_alphanumeric': 0.17737465356512974, 'fraction_numerical': 0.0, 'mean_word_length': 2.4018851756640958, 'pattern_counts': {'":': 0, '<': 49, '<?xml version=': 0, '>': 51, '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': '3988942', 'n_tokens_mistral': 1343, 'n_tokens_neox': 1289, 'n_words': 328}