Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: FMIndex can use other CSA, and selectLeftCursor #26

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions src/fmindex-collection/FMIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

namespace fmindex_collection {

template <OccTable Table>
template <OccTable Table, typename TCSA = CSA>
struct FMIndex {
static size_t constexpr Sigma = Table::Sigma;

using TTable = Table;

Table occ;
CSA csa;
TCSA csa;


FMIndex(std::span<uint8_t const> bwt, CSA _csa)
FMIndex(std::span<uint8_t const> bwt, TCSA _csa)
: occ{bwt}
, csa{std::move(_csa)}
{}
Expand All @@ -44,7 +43,7 @@ struct FMIndex {
auto [bwt, csa] = [&, &inputText=inputText, &inputSizes=inputSizes] () {
auto sa = createSA(inputText, threadNbr);
auto bwt = createBWT(inputText, sa);
auto csa = CSA{std::move(sa), samplingRate, inputSizes};
auto csa = TCSA{std::move(sa), samplingRate, inputSizes};

return std::make_tuple(std::move(bwt), std::move(csa));
}();
Expand Down
15 changes: 7 additions & 8 deletions src/fmindex-collection/search/SearchNoErrors.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,29 @@

namespace fmindex_collection::search_no_errors {

template <typename index_t, Sequence query_t, typename delegate_t>
void search(index_t const & index, query_t && query, delegate_t && delegate) {
using cursor_t = LeftBiFMIndexCursor<index_t>;
template <typename index_t, Sequence query_t>
auto search(index_t const & index, query_t && query) {
using cursor_t = select_left_cursor_t<index_t>;
static_assert(not cursor_t::Reversed, "reversed fmindex is not supported");

auto cur = cursor_t{index};
for (size_t i{0}; i < query.size(); ++i) {
auto r = query[query.size() - i - 1];
cur = cur.extendLeft(r);
if (cur.empty()) {
return;
return cur;
}
}
delegate(cur);
return cur;
}

template <typename index_t, Sequences queries_t, typename delegate_t>
void search(index_t const & index, queries_t && queries, delegate_t && delegate) {

for (size_t qidx{0}; qidx < queries.size(); ++qidx) {
auto const& query = queries[qidx];
search(index, query, [&qidx, &delegate](auto cursor) {
delegate(qidx, cursor);
});
auto cursor = search(index, query);
delegate(qidx, cursor);
}
}

Expand Down
23 changes: 19 additions & 4 deletions src/fmindex-collection/search/SelectCursor.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,33 @@ struct SelectIndexCursor<BiFMIndex<OccTable, TCSA>> {
using cursor_t = BiFMIndexCursor<BiFMIndex<OccTable, TCSA>>;
};

template <typename OccTable>
struct SelectIndexCursor<FMIndex<OccTable>> {
using cursor_t = FMIndexCursor<FMIndex<OccTable>>;
template <typename OccTable, typename TCSA>
struct SelectIndexCursor<FMIndex<OccTable, TCSA>> {
using cursor_t = FMIndexCursor<FMIndex<OccTable, TCSA>>;
};

template <typename OccTable, typename TCSA>
struct SelectIndexCursor<ReverseFMIndex<OccTable, TCSA>> {
using cursor_t = ReverseFMIndexCursor<ReverseFMIndex<OccTable, TCSA>>;
};

template <typename Index>
struct SelectLeftIndexCursor;

template <typename OccTable, typename TCSA>
struct SelectLeftIndexCursor<BiFMIndex<OccTable, TCSA>> {
using cursor_t = LeftBiFMIndexCursor<BiFMIndex<OccTable, TCSA>>;
};

template <typename OccTable, typename TCSA>
struct SelectLeftIndexCursor<FMIndex<OccTable, TCSA>> {
using cursor_t = FMIndexCursor<FMIndex<OccTable, TCSA>>;
};

template <typename Index>
using select_cursor_t = typename SelectIndexCursor<Index>::cursor_t;

template <typename Index>
using select_cursor_t = typename SelectIndexCursor<Index>::cursor_t;
using select_left_cursor_t = typename SelectLeftIndexCursor<Index>::cursor_t;

}