From 5712cbdcced08a6ce648fda7eec49f2d6f78b393 Mon Sep 17 00:00:00 2001 From: ZhangJian He Date: Tue, 2 Jul 2024 22:42:56 +0800 Subject: [PATCH] refactor: rename variable names for clarity in LCS method (#2392) --- .github/workflows/kvrocks.yaml | 2 +- src/types/redis_string.cc | 36 +++++++++++++++++----------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/kvrocks.yaml b/.github/workflows/kvrocks.yaml index 18089d5f993..06762033d8e 100644 --- a/.github/workflows/kvrocks.yaml +++ b/.github/workflows/kvrocks.yaml @@ -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 diff --git a/src/types/redis_string.cc b/src/types/redis_string.cc index b934f3b8d5d..43cf2a30924 100644 --- a/src/types/redis_string.cc +++ b/src/types/redis_string.cc @@ -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]) { @@ -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--; @@ -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(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; } }