From 013b489a6e560c8374f0bb7efef8c0f2905f4546 Mon Sep 17 00:00:00 2001 From: Simon Gene Gottlieb Date: Mon, 13 Jan 2025 17:04:13 +0100 Subject: [PATCH] feat: search with errors for VarIndex --- .../fmindex/VariableFMIndex.h | 37 ++++++++++++++----- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/fmindex-collection/fmindex/VariableFMIndex.h b/src/fmindex-collection/fmindex/VariableFMIndex.h index e0ef04b7..ac593504 100644 --- a/src/fmindex-collection/fmindex/VariableFMIndex.h +++ b/src/fmindex-collection/fmindex/VariableFMIndex.h @@ -7,6 +7,7 @@ #include "../occtable/all.h" #include "../rankvector/InterleavedBitvector.h" #include "../search/SearchNoErrors.h" +#include "../search/Backtracking.h" #include "FMIndex.h" #include @@ -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{}; query.resize(_query.size()); @@ -94,19 +95,35 @@ struct VariableFMIndex { } } - std::visit([&](I const& index) { - if constexpr (std::same_as) { - 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([&](I const& index) { + if constexpr (std::same_as) { + 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([&](I const& index) { + if constexpr (std::same_as) { + 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 void save(Archive& ar) const { ar(size_t{1}); // Version 1