Skip to content

Commit

Permalink
Keep the partial_queried vector within NamFinder so that we can re-us…
Browse files Browse the repository at this point in the history
…e it

Does not improve the speed!
  • Loading branch information
marcelm committed Oct 8, 2024
1 parent 1afc414 commit 6a5eca7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 19 deletions.
21 changes: 2 additions & 19 deletions src/nam.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,6 @@ bool operator==(const Match& lhs, const Match& rhs) {
return (lhs.query_start == rhs.query_start) && (lhs.query_end == rhs.query_end) && (lhs.ref_start == rhs.ref_start) && (lhs.ref_end == rhs.ref_end);
}

/*
* A partial hit is a hit where not the full randstrobe hash could be found in
* the index but only the "main" hash (only the first aux_len bits).
*/
struct PartialHit {
randstrobe_hash_t hash;
unsigned int start; // position in strobemer index
bool is_reverse;
bool operator==(const PartialHit& rhs) const {
return (hash == rhs.hash) && (start == rhs.start) && (is_reverse == rhs.is_reverse);
}
};

inline void add_to_matches_map_full(
robin_hood::unordered_map<unsigned int, std::vector<Match>>& matches_map,
int query_start,
Expand Down Expand Up @@ -200,11 +187,8 @@ std::vector<Nam> merge_matches_into_nams_forward_and_reverse(
* Return the fraction of nonrepetitive hits (those not above the filter_cutoff threshold)
*/
std::tuple<float, int, std::vector<Nam>> NamFinder::find(const QueryRandstrobeVector &query_randstrobes) const {
std::vector<PartialHit> partial_queried; // TODO: is a small set more efficient than linear search in a small vector?
if (use_mcs) {
partial_queried.reserve(10);
}
std::array<robin_hood::unordered_map<unsigned int, std::vector<Match>>, 2> matches_map;
partial_queried.clear();
matches_map[0].reserve(100);
matches_map[1].reserve(100);
int nr_good_hits = 0;
Expand Down Expand Up @@ -265,8 +249,7 @@ std::pair<int, std::vector<Nam>> NamFinder::find_rescue(
< std::tie(rhs.count, rhs.query_start, rhs.query_end);
}
};
std::vector<PartialHit> partial_queried; // TODO: is a small set more efficient than linear search in a small vector?
partial_queried.reserve(10);
partial_queried.clear();
std::array<robin_hood::unordered_map<unsigned int, std::vector<Match>>, 2> matches_map;
std::vector<RescueHit> hits_fw;
std::vector<RescueHit> hits_rc;
Expand Down
15 changes: 15 additions & 0 deletions src/nam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,19 @@ struct Nam {
}
};

/*
* A partial hit is a hit where not the full randstrobe hash could be found in
* the index but only the "main" hash (only the first aux_len bits).
*/
struct PartialHit {
randstrobe_hash_t hash;
unsigned int start; // position in strobemer index
bool is_reverse;
bool operator==(const PartialHit& rhs) const {
return (hash == rhs.hash) && (start == rhs.start) && (is_reverse == rhs.is_reverse);
}
};

struct NamFinder {
NamFinder(const StrobemerIndex& index, bool use_mcs)
: index(index)
Expand All @@ -50,6 +63,8 @@ struct NamFinder {
private:
const StrobemerIndex& index;
bool use_mcs;

mutable std::vector<PartialHit> partial_queried;
};

std::ostream& operator<<(std::ostream& os, const Nam& nam);
Expand Down

0 comments on commit 6a5eca7

Please sign in to comment.