Skip to content

Commit

Permalink
refactor: reduce cognitive complexity #220
Browse files Browse the repository at this point in the history
  • Loading branch information
fengelniederhammer committed Jan 19, 2024
1 parent 77eb32d commit 5404a6d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
5 changes: 5 additions & 0 deletions include/silo/storage/sequence_store.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ class SequenceStorePartition {

void fillIndexes(const vector<optional<string>>& genomes);

void addSymbolsToPositions(
const size_t& position,
SymbolMap<SymbolType, vector<uint32_t>>& ids_per_symbol_for_current_position
);

void fillNBitmaps(const vector<optional<string>>& genomes);

public:
Expand Down
37 changes: 22 additions & 15 deletions src/silo/storage/sequence_store.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,25 +171,33 @@ void SequenceStorePartition<SymbolType>::fillIndexes(const vector<optional<strin
);
}
}
for (const auto& symbol : SymbolType::SYMBOLS) {
if (!ids_per_symbol_for_current_position.at(symbol).empty()) {
positions[position].bitmaps[symbol].addMany(
ids_per_symbol_for_current_position.at(symbol).size(),
ids_per_symbol_for_current_position.at(symbol).data()
);
ids_per_symbol_for_current_position[symbol].clear();
}
if (symbol == positions[position].symbol_whose_bitmap_is_flipped) {
positions[position].bitmaps[symbol].flip(
sequence_count, sequence_count + number_of_sequences
);
}
}
addSymbolsToPositions(position, ids_per_symbol_for_current_position);
}
}
);
}

template <typename SymbolType>
void SequenceStorePartition<SymbolType>::addSymbolsToPositions(
const size_t& position,
SymbolMap<SymbolType, vector<uint32_t>>& ids_per_symbol_for_current_position
) {
for (const auto& symbol : SymbolType::SYMBOLS) {
if (!ids_per_symbol_for_current_position.at(symbol).empty()) {
positions[position].bitmaps[symbol].addMany(
ids_per_symbol_for_current_position.at(symbol).size(),
ids_per_symbol_for_current_position.at(symbol).data()
);
ids_per_symbol_for_current_position[symbol].clear();
}
if (symbol == positions[position].symbol_whose_bitmap_is_flipped) {
positions[position].bitmaps[symbol].flip(
sequence_count, sequence_count + positions.size()
);
}
}
}

template <typename SymbolType>
void SequenceStorePartition<SymbolType>::fillNBitmaps(const vector<optional<string>>& genomes) {
const size_t genome_length = positions.size();
Expand All @@ -198,7 +206,6 @@ void SequenceStorePartition<SymbolType>::fillNBitmaps(const vector<optional<stri

const tbb::blocked_range<size_t> range(0, genomes.size());
tbb::parallel_for(range, [&](const decltype(range)& local) {
// For every symbol, calculate all sequence IDs that have that symbol at that position
vector<uint32_t> positions_with_symbol_missing;
for (size_t sequence_index = local.begin(); sequence_index != local.end(); ++sequence_index) {
const auto& maybe_genome = genomes[sequence_index];
Expand Down

0 comments on commit 5404a6d

Please sign in to comment.