Program Listing for File table_simplifier.hpp

Return to documentation for file (fwdpp/ts/table_simplifier.hpp)

#ifndef FWDPP_TS_TABLE_SIMPLIFIER_HPP
#define FWDPP_TS_TABLE_SIMPLIFIER_HPP

#include <cmath>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cstddef>
#include <tuple>
#include <stdexcept>
#include "definitions.hpp"
#include "simplification/simplification.hpp"
#include "simplify_tables.hpp"

namespace fwdpp
{
    namespace ts
    {
        template <typename TableCollectionType> class table_simplifier
        {
          private:
            using simplifier_internal_state
                = simplification::simplifier_internal_state<TableCollectionType>;

            simplifier_internal_state _state;

          public:
            table_simplifier() : _state{}
            {
            }

            std::pair<std::vector<table_index_t>, std::vector<std::size_t>>
            simplify(TableCollectionType& tables,
                     const std::vector<table_index_t>& samples)
            {
                std::vector<table_index_t> idmap;
                std::vector<std::size_t> preserved_variants;
                simplify_tables(samples, simplification_flags{}, _state, tables, idmap,
                                preserved_variants);

                return std::make_pair(std::move(idmap), std::move(preserved_variants));
            }
        };

        template <typename TableCollectionType>
        inline table_simplifier<TableCollectionType>
        make_table_simplifier(const TableCollectionType&)
        {
            return table_simplifier<TableCollectionType>();
        }
    } // namespace ts
} // namespace fwdpp

#endif