<commit_before>#include <aleph/persistentHomology/ConnectedComponents.hh>

#include <aleph/topology/io/SimplicialComplexReader.hh>

#include <aleph/topology/Simplex.hh>
#include <aleph/topology/SimplicialComplex.hh>

#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <unordered_map>

using DataType          = double;
using VertexType        = unsigned;
using Simplex           = aleph::topology::Simplex<DataType, VertexType>;
using SimplicialComplex = aleph::topology::SimplicialComplex<Simplex>;
using Edge              = std::pair<VertexType, VertexType>;

namespace
{


struct SizeFunctor
{
  void initialize( VertexType v )
  {
    _componentSize[v] = 1;
  }

  void operator()( VertexType younger,
                   VertexType older,
                   DataType creation,
                   DataType destruction,
                   VertexType u,
                   VertexType v )
  {
    if( u > v )
      std::swap(u,v);

    _componentSize[older]                 += _componentSize[younger];
    _edgeRelevance[ std::make_pair(u,v) ]  = _componentSize[older];

    std::cerr << "* Edge " << "(" << u << "," << v << "): "
              << _edgeRelevance[ std::make_pair(u,v) ]
              << " "
              << "[" << creation << "," << destruction << "]"
              << "\n";
  }

  void operator()( VertexType /* root */,
                   DataType /* creation */ )
  {
  }

  std::unordered_map<VertexType, unsigned> _componentSize;
  std::map<Edge, unsigned>                 _edgeRelevance;
};

}

int main( int argc, char** argv )
{
  if( argc <= 1 )
    return -1;

  std::string filename = argv[1];

  SimplicialComplex K;

  aleph::topology::io::SimplicialComplexReader reader;
  reader( filename, K );

  SizeFunctor sf;

  auto&& tuple = aleph::calculateZeroDimensionalPersistenceDiagram<Simplex, aleph::traits::PersistencePairingCalculation<aleph::PersistencePairing<VertexType> > >( K, sf );
  auto&& pd    = std::get<0>( tuple );
  auto&& pp    = std::get<1>( tuple );

  std::cout << pd << "\n";
}<commit_msg>Added filtration ordering<commit_after>#include <aleph/persistentHomology/ConnectedComponents.hh>

#include <aleph/topology/filtrations/Data.hh>

#include <aleph/topology/io/SimplicialComplexReader.hh>

#include <aleph/topology/Simplex.hh>
#include <aleph/topology/SimplicialComplex.hh>

#include <iostream>
#include <map>
#include <string>
#include <utility>
#include <unordered_map>

using DataType          = double;
using VertexType        = unsigned;
using Simplex           = aleph::topology::Simplex<DataType, VertexType>;
using SimplicialComplex = aleph::topology::SimplicialComplex<Simplex>;
using Filtration        = aleph::topology::filtrations::Data<Simplex>;
using Edge              = std::pair<VertexType, VertexType>;

namespace
{


struct SizeFunctor
{
  void initialize( VertexType v )
  {
    _componentSize[v] = 1;
  }

  void operator()( VertexType younger,
                   VertexType older,
                   DataType creation,
                   DataType destruction,
                   VertexType u,
                   VertexType v )
  {
    if( u > v )
      std::swap(u,v);

    _componentSize[older]                 += _componentSize[younger];
    _edgeRelevance[ std::make_pair(u,v) ]  = _componentSize[older];

    std::cerr << "* Edge " << "(" << u << "," << v << "): "
              << _edgeRelevance[ std::make_pair(u,v) ]
              << " "
              << "[" << creation << "," << destruction << "]"
              << "\n";
  }

  void operator()( VertexType /* root */,
                   DataType /* creation */ )
  {
  }

  std::unordered_map<VertexType, unsigned> _componentSize;
  std::map<Edge, unsigned>                 _edgeRelevance;
};

}

int main( int argc, char** argv )
{
  if( argc <= 1 )
    return -1;

  std::string filename = argv[1];

  SimplicialComplex K;

  aleph::topology::io::SimplicialComplexReader reader;
  reader( filename, K );

  K.sort( Filtration() );

  SizeFunctor sf;

  auto&& tuple = aleph::calculateZeroDimensionalPersistenceDiagram<Simplex, aleph::traits::PersistencePairingCalculation<aleph::PersistencePairing<VertexType> > >( K, sf );
  auto&& pd    = std::get<0>( tuple );
  auto&& pp    = std::get<1>( tuple );

  std::cout << pd << "\n";
}
{'fraction_non_alphanumeric': 0.14412107101280558, 'fraction_numerical': 0.0027939464493597207, 'mean_word_length': 2.7552447552447554, 'pattern_counts': {'":': 0, '<': 109, '<?xml version=': 0, '>': 45, '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': '93706', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1331, 'n_words': 265}