Skip to content

Commit 229d0df

Browse files
committed
Refactor: Convert hits_fw/hits_rc into array
1 parent 3c568dc commit 229d0df

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

src/nam.cpp

+8-17
Original file line numberDiff line numberDiff line change
@@ -264,43 +264,34 @@ std::pair<int, std::vector<Nam>> find_nams_rescue(
264264
}
265265
};
266266
std::array<robin_hood::unordered_map<unsigned int, std::vector<Match>>, 2> matches_map;
267-
std::vector<RescueHit> hits_fw;
268-
std::vector<RescueHit> hits_rc;
267+
std::array<std::vector<RescueHit>, 2> hits;
269268
matches_map[0].reserve(100);
270269
matches_map[1].reserve(100);
271-
hits_fw.reserve(5000);
272-
hits_rc.reserve(5000);
270+
hits[0].reserve(5000);
271+
hits[1].reserve(5000);
273272

274273
for (auto &qr : query_randstrobes) {
275274
size_t position = index.find_full(qr.hash);
276275
if (position != index.end()) {
277276
unsigned int count = index.get_count_full(position);
278277
RescueHit rh{position, count, qr.start, qr.end, false};
279-
if (qr.is_reverse){
280-
hits_rc.push_back(rh);
281-
} else {
282-
hits_fw.push_back(rh);
283-
}
278+
hits[qr.is_reverse].push_back(rh);
284279
}
285280
else if (use_mcs) {
286281
size_t partial_pos = index.find_partial(qr.hash);
287282
if (partial_pos != index.end()) {
288283
unsigned int partial_count = index.get_count_partial(partial_pos);
289284
RescueHit rh{partial_pos, partial_count, qr.start, qr.start + index.k(), true};
290-
if (qr.is_reverse){
291-
hits_rc.push_back(rh);
292-
} else {
293-
hits_fw.push_back(rh);
294-
}
285+
hits[qr.is_reverse].push_back(rh);
295286
}
296287
}
297288
}
298289

299-
std::sort(hits_fw.begin(), hits_fw.end());
300-
std::sort(hits_rc.begin(), hits_rc.end());
290+
std::sort(hits[0].begin(), hits[0].end());
291+
std::sort(hits[1].begin(), hits[1].end());
301292
int n_hits = 0;
302293
size_t is_revcomp = 0;
303-
for (auto& rescue_hits : {hits_fw, hits_rc}) {
294+
for (auto& rescue_hits : hits) {
304295
int cnt = 0;
305296
for (auto &rh : rescue_hits) {
306297
if ((rh.count > rescue_cutoff && cnt >= 5) || rh.count > 1000) {

0 commit comments

Comments
 (0)