[PATCH] D44720: [clangd] Simplify fuzzy matcher (sequence alignment) by removing some condition checks.
Fangrui Song via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Mar 29 12:14:01 PDT 2018
MaskRay added a comment.
In `buildGraph`, the nested loop
for (int P = 0; P < PatN; ++P) {
// Scores[P + 1][P][Miss] = Scores[P + 1][P][Match] = {AwfulScore, Miss};
for (int W = P; W < WordN; ++W) {
is interpreted as: we are calculating the cell `Scores[P+1][W+1][*]`, using the characters `Pattern[P]` and `Word[W]`. This is a position central viewpoint.
If you see `P and W` as numbers of characters, instead of the string indices, will it make more sense due to alleviated +1 -1 mental burden?
It can also be rephrased as:
for (int P = 1; P <= PatN; ++P) {
for (int W = P + 1; W <= WordN; ++W) { // Since you like this form (though I don't)
This is a cell central viewpoint.
(we are calculating the cell `Scores[P][W][*]`, using the characters `Pattern[P-1]` and `Word[W-1]`)
The former interpretation is preferred because half closed intervals are generally preferred.
In the table dumping stage,
for (int I = W; i > 0; i--)
is better than
for (int I = W - 1; I >= 0; --I)
because we are tracing through the optimal path of the dynamic programming *cells*. We are also tracing the `W P` positions, but the former interpretation gets rid of some +1 -1.
Repository:
rCTE Clang Tools Extra
https://reviews.llvm.org/D44720
More information about the cfe-commits
mailing list