Skip to content

Commit

Permalink
Merge pull request #74 from SGSSGene/feat/use_search_with_errors_on_v…
Browse files Browse the repository at this point in the history
…ariableindex

feat: search with errors for VarIndex
  • Loading branch information
SGSSGene authored Jan 13, 2025
2 parents 3b9f3f3 + 3b1b3b2 commit c16047a
Showing 1 changed file with 27 additions and 10 deletions.
37 changes: 27 additions & 10 deletions src/fmindex-collection/fmindex/VariableFMIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "../occtable/all.h"
#include "../rankvector/InterleavedBitvector.h"
#include "../search/SearchNoErrors.h"
#include "../search/Backtracking.h"
#include "FMIndex.h"

#include <variant>
Expand Down Expand Up @@ -74,7 +75,7 @@ struct VariableFMIndex {
}
}

auto search(std::string const& _query) const {
auto search(std::string const& _query, size_t k) const {
// convert query to compact rank representation
auto query = std::vector<uint8_t>{};
query.resize(_query.size());
Expand All @@ -94,19 +95,35 @@ struct VariableFMIndex {
}
}

std::visit([&]<typename I>(I const& index) {
if constexpr (std::same_as<I, std::monostate>) {
return;
} else {
auto cursor = search_no_errors::search(index, query);
for (auto [seqId, pos] : LocateLinear{index, cursor}) {
result.emplace_back(seqId, pos);
if (k == 0) {
std::visit([&]<typename I>(I const& index) {
if constexpr (std::same_as<I, std::monostate>) {
return;
} else {
auto cursor = search_no_errors::search(index, query);
for (auto [seqId, pos] : LocateLinear{index, cursor}) {
result.emplace_back(seqId, pos);
}
}
}
}, index);
}, index);
} else {
std::visit([&]<typename I>(I const& index) {
if constexpr (std::same_as<I, std::monostate>) {
return;
} else {
search_backtracking::search(index, query, k, [&](auto cursor, auto errors) {
(void)errors;
for (auto [seqId, pos] : LocateLinear{index, cursor}) {
result.emplace_back(seqId, pos);
}
});
}
}, index);
}
return result;
}


template <typename Archive>
void save(Archive& ar) const {
ar(size_t{1}); // Version 1
Expand Down

0 comments on commit c16047a

Please sign in to comment.