Skip to content

Commit 94640e1

Browse files
committed
fix: bug in BiFMIndexKStepCursor
1 parent c19e584 commit 94640e1

File tree

3 files changed

+291
-946
lines changed

3 files changed

+291
-946
lines changed

src/fmindex-collection/fmindex/BiFMIndexKStepCursor.h

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ struct BiFMIndexKStepCursor {
8080
auto& bwt = index->bwt_kstep;
8181
bwt.template all_ranks_dual_limit<bitct>(lb, lb+len, [&](size_t symb, size_t rs1, size_t rs2, size_t prs1, size_t prs2) {
8282
auto newLb = index->C[symb] + rs1;
83-
auto newLen = rs2 - rs1;
8483
auto newLbRev = lbRev + prs2 - prs1;
84+
auto newLen = rs2 - rs1;
8585
cursors[symb] = BiFMIndexKStepCursor{*index, newLb, newLbRev, newLen, steps+1};
8686
});
8787
} else {
@@ -96,14 +96,14 @@ struct BiFMIndexKStepCursor {
9696
if constexpr (HasDualRank) {
9797
auto& bwt = fetchRightBwtKStep();
9898
bwt.template all_ranks_dual_limit<bitct>(lbRev, lbRev+len, [&](size_t symb, size_t rs1, size_t rs2, size_t prs1, size_t prs2) {
99+
auto newLb = lb + prs2 - prs1;
99100
auto newLbRev = index->C[symb] + rs1;
100101
auto newLen = rs2 - rs1;
101-
auto newLb = lb + prs2 - prs1;
102102
cursors[symb] = BiFMIndexKStepCursor{*index, newLb, newLbRev, newLen, steps+1};
103103
});
104104
} else {
105105
for (size_t i{0}; i < Sigma; ++i) {
106-
cursors[i] = extendLeft(i);
106+
cursors[i] = extendRight(i);
107107
}
108108
}
109109
return cursors;
@@ -114,10 +114,10 @@ struct BiFMIndexKStepCursor {
114114
auto [lb_pr, lb_r] = bwt.template prefix_rank_and_rank_limit<bitct>(lb, symb);
115115
auto [rb_pr, rb_r] = bwt.template prefix_rank_and_rank_limit<bitct>(lb+len, symb);
116116

117-
size_t newLb = lb_r;
117+
size_t newLb = lb_r + index->C[symb];
118118
size_t newLbRev = lbRev + rb_pr - lb_pr;
119-
size_t newLen = rb_r - newLb;
120-
auto newCursor = BiFMIndexKStepCursor{*index, newLb + index->C[symb], newLbRev, newLen, steps+1};
119+
size_t newLen = rb_r - lb_r;
120+
auto newCursor = BiFMIndexKStepCursor{*index, newLb, newLbRev, newLen, steps+1};
121121
return newCursor;
122122
}
123123
auto extendRight(size_t symb) const -> BiFMIndexKStepCursor {
@@ -126,10 +126,10 @@ struct BiFMIndexKStepCursor {
126126
auto [lb_pr, lb_r] = bwt.template prefix_rank_and_rank_limit<bitct>(lbRev, symb);
127127
auto [rb_pr, rb_r] = bwt.template prefix_rank_and_rank_limit<bitct>(lbRev+len, symb);
128128

129-
size_t newLbRev = lb_r;
130129
size_t newLb = lb + rb_pr - lb_pr;
131-
size_t newLen = rb_r - newLbRev;
132-
auto newCursor = BiFMIndexKStepCursor{*index, newLb, newLbRev + index->C[symb], newLen, steps+1};
130+
size_t newLbRev = lb_r + index->C[symb];
131+
size_t newLen = rb_r - lb_r;
132+
auto newCursor = BiFMIndexKStepCursor{*index, newLb, newLbRev, newLen, steps+1};
133133
return newCursor;
134134
}
135135

@@ -247,7 +247,7 @@ struct BiFMIndexKStepCursor {
247247
size_t newLb = bwt.rank(lb, kSymb);
248248
size_t newLbRev = lbRev;
249249
size_t newLen = len;
250-
auto newCursor = BiFMIndexKStepCursor{*index, newLb + index->C_kstep[kSymb], newLbRev, newLen, steps+1};
250+
auto newCursor = BiFMIndexKStepCursor{*index, newLb + index->C_kstep[kSymb], newLbRev, newLen, steps+KStep};
251251
return newCursor;
252252
}
253253

@@ -257,7 +257,7 @@ struct BiFMIndexKStepCursor {
257257
size_t newLb = lb;
258258
size_t newLbRev = bwt.rank(lbRev, kSymb);
259259
size_t newLen = len;
260-
auto newCursor = BiFMIndexKStepCursor{*index, newLb, newLbRev + index->CRev_kstep[kSymb], newLen, steps+1};
260+
auto newCursor = BiFMIndexKStepCursor{*index, newLb, newLbRev + index->CRev_kstep[kSymb], newLen, steps+KStep};
261261
return newCursor;
262262
}
263263

src/fmindex-collection/search/SearchNg28.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ struct Search {
237237
if (cur.count() == 1) {
238238
auto s = (dir == dir_t::Right)?cur.symbolRight():cur.symbolLeft();
239239
if (s != nextSymb) return false;
240-
if constexpr (requires() { { cur.extendRightBySymbol() }; }) {
240+
if constexpr (requires() { { cur.extendRightBySymbol(nextSymb) }; }) {
241241
cur = (dir == dir_t::Right)?cur.extendRightBySymbol(nextSymb):cur.extendLeftBySymbol(nextSymb);
242242
} else {
243243
cur = (dir == dir_t::Right)?cur.extendRight(nextSymb):cur.extendLeft(nextSymb);

0 commit comments

Comments
 (0)