Skip to content

Commit

Permalink
refactor: rename variable names for clarity in LCS method (#2392)
Browse files Browse the repository at this point in the history
  • Loading branch information
shoothzj committed Jul 2, 2024
1 parent f1c5acb commit 5712cbd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 19 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/kvrocks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Check typos
uses: crate-ci/typos@v1.18.2
uses: crate-ci/typos@v1.22.9
with:
config: .github/config/typos.toml

Expand Down
36 changes: 18 additions & 18 deletions src/types/redis_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -597,10 +597,10 @@ rocksdb::Status String::LCS(const std::string &user_key1, const std::string &use

uint32_t i = alen;
uint32_t j = blen;
uint32_t arange_start = alen; // alen signals that values are not set.
uint32_t arange_end = 0;
uint32_t brange_start = 0;
uint32_t brange_end = 0;
uint32_t a_range_start = alen; // alen signals that values are not set.
uint32_t a_range_end = 0;
uint32_t b_range_start = 0;
uint32_t b_range_end = 0;
while (i > 0 && j > 0) {
bool emit_range = false;
if (a[i - 1] == b[j - 1]) {
Expand All @@ -611,24 +611,24 @@ rocksdb::Status String::LCS(const std::string &user_key1, const std::string &use
}

// Track the current range.
if (arange_start == alen) {
arange_start = i - 1;
arange_end = i - 1;
brange_start = j - 1;
brange_end = j - 1;
if (a_range_start == alen) {
a_range_start = i - 1;
a_range_end = i - 1;
b_range_start = j - 1;
b_range_end = j - 1;
}
// Let's see if we can extend the range backward since
// it is contiguous.
else if (arange_start == i && brange_start == j) {
arange_start--;
brange_start--;
else if (a_range_start == i && b_range_start == j) {
a_range_start--;
b_range_start--;
} else {
emit_range = true;
}

// Emit the range if we matched with the first byte of
// one of the two strings. We'll exit the loop ASAP.
if (arange_start == 0 || brange_start == 0) {
if (a_range_start == 0 || b_range_start == 0) {
emit_range = true;
}
idx--;
Expand All @@ -643,23 +643,23 @@ rocksdb::Status String::LCS(const std::string &user_key1, const std::string &use
i--;
else
j--;
if (arange_start != alen) emit_range = true;
if (a_range_start != alen) emit_range = true;
}

// Emit the current range if needed.
if (emit_range) {
if (auto result = std::get_if<StringLCSIdxResult>(rst)) {
uint32_t match_len = arange_end - arange_start + 1;
uint32_t match_len = a_range_end - a_range_start + 1;

// Always emit the range when the `min_match_len` is not set.
if (args.min_match_len == 0 || match_len >= args.min_match_len) {
result->matches.emplace_back(StringLCSRange{arange_start, arange_end},
StringLCSRange{brange_start, brange_end}, match_len);
result->matches.emplace_back(StringLCSRange{a_range_start, a_range_end},
StringLCSRange{b_range_start, b_range_end}, match_len);
}
}

// Restart at the next match.
arange_start = alen;
a_range_start = alen;
}
}

Expand Down

0 comments on commit 5712cbd

Please sign in to comment.