<commit_before>// dune-multiscale
// Copyright Holders: <NAME>, <NAME>
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#ifndef DUNE_MS__TOOLS_MISC_HH
#define DUNE_MS__TOOLS_MISC_HH

#include <dune/stuff/common/string.hh>
#include <dune/grid/common/entitypointer.hh>
#include <dune/grid/common/indexidset.hh>

namespace Dune {
namespace Stuff {
namespace Grid {

//!
template < class GridImp, class IteratorImp, class IndexSetImp, class IndexTypeImp>
EntityPointer< const GridImp, IteratorImp > make_father(const IndexSet< GridImp, IndexSetImp, IndexTypeImp >& index_set,
                EntityPointer< const GridImp, IteratorImp > entity )
{
  bool father_found = false;
  auto test_entity = entity;
  while (!father_found)
  {
    if (index_set.contains(*test_entity))
    {
      entity = test_entity;
    }

    if (!test_entity->hasFather())
    {
      father_found = true;
    } else {
      test_entity = test_entity->father();
    }
  }
  return entity;
}


template < class GridImp, class IteratorImp, class IndexSetImp, class IndexTypeImp >
EntityPointer< const GridImp, IteratorImp > make_father(const IndexSet< GridImp, IndexSetImp, IndexTypeImp >& index_set,
                 EntityPointer< const GridImp, IteratorImp > entity,
                 int level_difference)
{
    for (int lev = 0; lev < level_difference; ++lev)
          entity = entity->father();
    return make_father(index_set, entity);
}

template < int cd, int dim,<commit_msg>hopefully fix make_father for all compilers/grid managers<commit_after>// dune-multiscale
// Copyright Holders: <NAME>, <NAME>
// License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

#ifndef DUNE_MS__TOOLS_MISC_HH
#define DUNE_MS__TOOLS_MISC_HH

#include <dune/stuff/common/string.hh>
#include <dune/grid/common/entitypointer.hh>
#include <dune/grid/common/indexidset.hh>

namespace Dune {
namespace Stuff {
namespace Grid {

/** ConstGridImp is supposed to be identical to const GridImp, alas different grid managers
 *  and different type deduction between gcc/clang make two different types necessary here
 */
template < class GridImp, class ConstGridImp, class IteratorImp, class IndexSetImp, class IndexTypeImp>
EntityPointer< GridImp, IteratorImp > make_father(const IndexSet< ConstGridImp, IndexSetImp, IndexTypeImp >& index_set,
                EntityPointer< GridImp, IteratorImp > entity )
{
  bool father_found = false;
  auto test_entity = entity;
  while (!father_found)
  {
    if (index_set.contains(*test_entity))
    {
      entity = test_entity;
    }

    if (!test_entity->hasFather())
    {
      father_found = true;
    } else {
      test_entity = test_entity->father();
    }
  }
  return entity;
}


template < class GridImp, class ConstGridImp, class IteratorImp, class IndexSetImp, class IndexTypeImp >
EntityPointer< GridImp, IteratorImp > make_father(const IndexSet< ConstGridImp, IndexSetImp, IndexTypeImp >& index_set,
                 EntityPointer< GridImp, IteratorImp > entity,
                 int level_difference)
{
    for (int lev = 0; lev < level_difference; ++lev)
          entity = entity->father();
    return make_father(index_set, entity);
}

template < int cd, int dim,
{'fraction_non_alphanumeric': 0.10151655834107087, 'fraction_numerical': 0.0018570102135561746, 'mean_word_length': 3.788148148148148, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, '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': '217348', 'n_tokens_mistral': 1031, 'n_tokens_neox': 1002, 'n_words': 260}