...
 
Commits (4)
......@@ -21,20 +21,55 @@ void BinReadStorage::init(size_t nb_bins, size_t max_score, const VirtualReadSco
if (inited)
return;
this->nb_bins = nb_bins;
this->nb_bins = 0;
this->max_bins = nb_bins;
this->max_score = max_score;
if (no_list)
bins = NULL;
else
bins = new list<Sequence>[nb_bins+1];
bins = new list<Sequence>[1];
score_bins = new double[1];
nb_scores = new size_t[1];
score_bins[0] = 0;
nb_scores[0] = 0;
scorer = vrs;
inited=true;
}
void BinReadStorage::reallocate(){
list<Sequence> tmpBin;
nb_bins = max_bins;
for(std::list<Sequence>::iterator it = bins[0].begin(); it != bins[0].end(); ++it){
tmpBin.push_back(*it);
}
if(bins){
delete [] bins;
}
if(score_bins){
delete [] score_bins;
}
if(nb_scores){
delete [] nb_scores;
}
bins = new list<Sequence>[nb_bins+1];
score_bins = new double[nb_bins+1];
nb_scores = new size_t[nb_bins+1];
for (size_t i = 0; i <= nb_bins; i++) {
for(int i = 0; i <= nb_bins; ++i){
score_bins[i] = 0;
nb_scores[i] = 0;
}
scorer = vrs;
inited=true;
all_read_lengths = 0;
for(auto s : tmpBin){
float score = scorer->getScore(s);
size_t bin = scoreToBin(score);
addScore(bin, score);
all_read_lengths += s.sequence.length();
bins[bin].push_back(s);
}
}
BinReadStorage::~BinReadStorage() {
......@@ -74,7 +109,10 @@ void BinReadStorage::add(Sequence &s) {
} else {
// We don't have space left.
// Either we don't insert that sequence or it replaces another one
if (bin > smallest_bin_not_empty) {
if(nb_inserted == nb_stored){
reallocate();
}
if (bin > smallest_bin_not_empty) {
bins[smallest_bin_not_empty].erase(bins[smallest_bin_not_empty].begin());
if (bins[smallest_bin_not_empty].size() == 0)
update_smallest_bin_not_empty();
......
......@@ -68,6 +68,7 @@ class VirtualReadStorage {
*/
class BinReadStorage: public VirtualReadStorage {
private:
size_t max_bins;
size_t nb_bins;
list<Sequence> *bins;
double *score_bins;
......@@ -94,6 +95,11 @@ public:
*/
void init(size_t nb_bins, size_t max_score, const VirtualReadScore *vrs, bool no_list = false);
/**
* If the bin is full we need, the storage needs to be reallocated to have more memory.
*/
void reallocate();
~BinReadStorage();
void add(Sequence &s);
......