void add_new_mutation( const std::size_t idx, const mcont_t & mutations, gamete_type & new_gamete ) { assert(idx<mutations.size()); if(mutations[idx].neutral) { assert(std::find(new_gamete.mutations.begin(), new_gamete.mutations.end(),idx)==new_gamete.mutations.end()); new_gamete.mutations.emplace(std::upper_bound(new_gamete.mutations.begin(), new_gamete.mutations.end(),mutations[idx].pos, [&mutations](const double & __value,const std::size_t __mut) noexcept { assert(__mut<mutations.size()); return __value < mutations[__mut].pos;}), idx ); assert(gamete_is_sorted_n(new_gamete,mutations)); } else { assert(std::find(new_gamete.smutations.begin(), new_gamete.smutations.end(),idx)==new_gamete.smutations.end()); new_gamete.smutations.emplace(std::upper_bound(new_gamete.smutations.begin(), new_gamete.smutations.end(),mutations[idx].pos, [&mutations](const double & __value,const std::size_t __mut) noexcept { assert(__mut<mutations.size()); return __value < mutations[__mut].pos;}), idx ); assert(gamete_is_sorted_s(new_gamete,mutations)); } }
inline void process_gametes( const gcont_t & gametes, const mcont_t & mutations, std::vector<uint_t> & mcounts) /*! For every non-extinct gamete, increment the count of its mutations using the frequency of the gamete. This is usually the most expensive function call in a simulation. */ { if(mutations.size()>mcounts.size()) { mcounts.resize(mutations.size(),0); } //zero out mcounts for(auto & mc : mcounts) mc=0; //update mutation counts for(const auto & g : gametes) { if(g.n) //only do this for extant gametes { for(const auto & m : g.mutations) mcounts[m]+=g.n; for(const auto & m : g.smutations) mcounts[m]+=g.n; } } }
//! Empty all the containers void clear_containers() { mutations.clear(); mcounts.clear(); mcounts_from_preserved_nodes.clear(); gametes.clear(); mut_lookup.clear(); fixations.clear(); fixation_times.clear(); }
inline itr_type rec_update_itr( itr_type __first, itr_type __last, const mcont_t & mutations, const double & val) { if(__first==__last) return __first; return std::upper_bound(__first,__last, std::cref(val), [&mutations](const double __val,const std::size_t __mut) noexcept { assert(__mut < mutations.size()); return __val < mutations[__mut].pos; }); }
inline void process_gametes( const gcont_t & gametes, const mcont_t & mutations, std::vector<uint_t> & mcounts) /*! For every non-extinct gamete, increment the counts of its mutations via a call to KTfwd::fwdpp_internal::adjust_mutation_counts. */ { if(mutations.size()>mcounts.size()) { mcounts.resize(mutations.size(),0); } //zero out mcounts for(auto & mc : mcounts) mc=0; //update mutation counts for(const auto & g : gametes) { if(g.n) //only do this for extant gametes { for(const auto & m : g.mutations) mcounts[m]+=g.n; for(const auto & m : g.smutations) mcounts[m]+=g.n; } } }