Commit 2e5ca4cb authored by Mikaël Salson's avatar Mikaël Salson Committed by Mathieu Giraud

automaton.hpp: Precompute the global index load

This prevents from recomputing it each time
parent d3b4db3c
...@@ -24,6 +24,7 @@ class AbstractACAutomaton: public IKmerStore<Info> { ...@@ -24,6 +24,7 @@ class AbstractACAutomaton: public IKmerStore<Info> {
protected: protected:
void *initialState; void *initialState;
float all_index_load;
map<Info, size_t> kmers_inserted; map<Info, size_t> kmers_inserted;
public: public:
AbstractACAutomaton(); AbstractACAutomaton();
......
...@@ -15,16 +15,16 @@ void AbstractACAutomaton<Info>::finish_building() { ...@@ -15,16 +15,16 @@ void AbstractACAutomaton<Info>::finish_building() {
IKmerStore<Info>::finish_building(); IKmerStore<Info>::finish_building();
build_failure_functions(); build_failure_functions();
} }
all_index_load = 0;
for(auto iter: kmers_inserted) {
all_index_load += getIndexLoad(iter.first);
}
} }
template<class Info> template<class Info>
float AbstractACAutomaton<Info>::getIndexLoad(Info kmer) const { float AbstractACAutomaton<Info>::getIndexLoad(Info kmer) const {
float load = 0;
if (kmers_inserted.count(kmer) == 0) { if (kmers_inserted.count(kmer) == 0) {
for(auto iter: kmers_inserted) { return (kmer.isUnknown()) ? 1 - all_index_load : all_index_load;
load += getIndexLoad(iter.first);
}
return (kmer.isUnknown()) ? 1 - load : load;
} else { } else {
return kmers_inserted.at(kmer) / pow(4.0, kmer.getLength()); return kmers_inserted.at(kmer) / pow(4.0, kmer.getLength());
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment