From: <si...@us...> - 2012-03-30 03:20:20
|
Revision: 4535 http://simupop.svn.sourceforge.net/simupop/?rev=4535&view=rev Author: simupop Date: 2012-03-30 03:20:13 +0000 (Fri, 30 Mar 2012) Log Message: ----------- Greatly simplify fillGenotype Modified Paths: -------------- trunk/src/mutant_vector.h trunk/src/transmitter.cpp trunk/src/utility.cpp trunk/src/utility.h Modified: trunk/src/mutant_vector.h =================================================================== --- trunk/src/mutant_vector.h 2012-03-30 02:59:08 UTC (rev 4534) +++ trunk/src/mutant_vector.h 2012-03-30 03:20:13 UTC (rev 4535) @@ -414,6 +414,17 @@ storage_invariants(); } + // clear some ... added by Bo + inline void clear(size_t beg, size_t end) + { + if (beg == end) + return; + BOOST_UBLAS_CHECK(beg < end && end <= size_, external_logic()); + size_t b = _lower_bound(index_data_.begin(), index_data_.begin() + filled_, beg, std::less<size_type> ()) - index_data_.begin(); + size_t e = _lower_bound(index_data_.begin(), index_data_.begin() + filled_, end, std::less<size_type> ()) - index_data_.begin(); + for (size_t i = b; i < e; ++i) + value_data_[i] = 0; + } class const_val_iterator; @@ -794,6 +805,16 @@ } + size_t index() const + { + return m_index; + } + + val_iterator getValIterator() const + { + return (*this)().val_begin(m_index); + } + const_reference value() const { static const Allele zero = 0; @@ -1226,6 +1247,16 @@ } + size_t index() const + { + return m_index; + } + + const_val_iterator getValIterator() const + { + return (*this)().val_begin(m_index); + } + const_reference value() const { static const Allele zero = 0; Modified: trunk/src/transmitter.cpp =================================================================== --- trunk/src/transmitter.cpp 2012-03-30 02:59:08 UTC (rev 4534) +++ trunk/src/transmitter.cpp 2012-03-30 03:20:13 UTC (rev 4535) @@ -64,8 +64,8 @@ #else DBG_FAILIF(m_chromIdx.empty(), ValueError, "GenoTransmitter is not initialized properly"); # ifdef MUTANTALLELE - fillGenotype(ind.genoBegin(ploidy) + m_chromIdx[chrom], - ind.genoBegin(ploidy) + m_chromIdx[chrom + 1], 0); + clearGenotype(ind.genoBegin(ploidy) + m_chromIdx[chrom], + ind.genoBegin(ploidy) + m_chromIdx[chrom + 1]); # else fill(ind.genoBegin(ploidy) + m_chromIdx[chrom], ind.genoBegin(ploidy) + m_chromIdx[chrom + 1], 0); Modified: trunk/src/utility.cpp =================================================================== --- trunk/src/utility.cpp 2012-03-30 02:59:08 UTC (rev 4534) +++ trunk/src/utility.cpp 2012-03-30 03:20:13 UTC (rev 4535) @@ -4559,38 +4559,9 @@ } -void fillGenotype(GenoIterator begin, GenoIterator end, Allele value) +void clearGenotype(GenoIterator begin, GenoIterator end) { - vectorm::index_array_type::iterator index_begin = begin.getIndexIterator(); - vectorm::index_array_type::iterator index_end = end.getIndexIterator(); - vectorm::value_array_type::iterator value_begin = begin.getValueIterator(); - size_t diff_size = index_end - index_begin; - size_t filled_size = begin.getContainer()->filled(); - - if (value == 0) { - std::copy(index_begin + diff_size, begin.getContainer()->index_data().begin() + filled_size, index_begin); - std::copy(value_begin + diff_size, begin.getContainer()->value_data().begin() + filled_size, value_begin); - begin.getContainer()->set_filled(filled_size - diff_size); - // If the fill function is extensively use, reserve() can be remove in order to improve performance . - begin.getContainer()->reserve(filled_size - diff_size); - } else { - size_t value_size = end - begin; - size_t insert_size = value_size - diff_size; - if (filled_size + insert_size >= begin.getContainer()->nnz_capacity()) { - begin.getContainer()->reserve(filled_size + insert_size, true); - // After using reserve(), index_begin and value_begin no longer valid, get a new one - index_begin = begin.getIndexIterator(); - value_begin = begin.getValueIterator(); - } - std::copy_backward(index_begin, begin.getContainer()->index_data().begin() + filled_size, begin.getContainer()->index_data().begin() + filled_size + insert_size); - for (size_t i = 0; i < value_size; i++) { - *(index_begin + i) = *index_begin + i; - } - std::copy_backward(value_begin, begin.getContainer()->value_data().begin() + filled_size, begin.getContainer()->value_data().begin() + filled_size + insert_size); - std::fill(value_begin, value_begin + value_size, value); - begin.getContainer()->set_filled(filled_size + insert_size); - - } + begin.getContainer()->clear(begin.index(), end.index()); } Modified: trunk/src/utility.h =================================================================== --- trunk/src/utility.h 2012-03-30 02:59:08 UTC (rev 4534) +++ trunk/src/utility.h 2012-03-30 03:20:13 UTC (rev 4535) @@ -2147,7 +2147,7 @@ void copyGenotype(ConstGenoIterator begin, ConstGenoIterator end, GenoIterator it); /// CPPONLY -void fillGenotype(GenoIterator begin, GenoIterator end, Allele value); +void clearGenotype(GenoIterator begin, GenoIterator end); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |