Skip to content

Commit

Permalink
release v1.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
maxbachmann committed Jul 29, 2022
1 parent 3db25cc commit d937555
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 7 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
## Changelog

### [1.1.1] - 2022-07-29
#### Performance
- improve performance for banded Levenshtein implementation

### [1.1.0] - 2022-07-29
#### Fixed
- fix banded Levenshtein implementation
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ if (CMAKE_BINARY_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
message(FATAL_ERROR "Building in-source is not supported! Create a build dir and remove ${CMAKE_SOURCE_DIR}/CMakeCache.txt")
endif()

project(rapidfuzz LANGUAGES CXX VERSION 1.1.0)
project(rapidfuzz LANGUAGES CXX VERSION 1.1.1)

list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake")
include(GNUInstallDirs)
Expand Down
38 changes: 32 additions & 6 deletions rapidfuzz/distance/Levenshtein.impl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,8 @@ int64_t levenshtein_hyrroe2003_small_band(const BlockPatternMatchVector& PM, Ran
ptrdiff_t start_pos = max + 1 - 64;

/* Searching */
for (ptrdiff_t i = 0; i < s2.size(); ++i,++start_pos) {
ptrdiff_t i = 0;
for (; i < s1.size() - max; ++i,++start_pos) {
/* Step 1: Computing D0 */
uint64_t PM_j = 0;
if (start_pos < 0)
Expand All @@ -253,16 +254,41 @@ int64_t levenshtein_hyrroe2003_small_band(const BlockPatternMatchVector& PM, Ran
uint64_t HN = D0 & VP;

/* Step 3: Computing the value D[m,j] */
if (i < s1.size() - max)
currDist += !bool(D0 & diagonal_mask);

/* Step 4: Computing Vp and VN */
VP = HN | ~((D0 >> 1) | HP);
VN = (D0 >> 1) & HP;
}

for (; i < s2.size(); ++i,++start_pos) {
/* Step 1: Computing D0 */
uint64_t PM_j = 0;
if (start_pos < 0)
{
currDist += !bool(D0 & diagonal_mask);
PM_j = PM.get(0, s2[i]) << (-start_pos);
}
else
{
currDist += bool(HP & horizontal_mask);
currDist -= bool(HN & horizontal_mask);
horizontal_mask >>= 1;
size_t word = static_cast<size_t>(start_pos) / 64;
size_t word_pos = static_cast<size_t>(start_pos) % 64;

PM_j = PM.get(word, s2[i]) >> word_pos;

if (word + 1 < words && word_pos != 0)
PM_j |= PM.get(word + 1, s2[i]) << (64 - word_pos);
}
uint64_t X = PM_j;
uint64_t D0 = (((X & VP) + VP) ^ VP) | X | VN;

/* Step 2: Computing HP and HN */
uint64_t HP = VN | ~(D0 | VP);
uint64_t HN = D0 & VP;

/* Step 3: Computing the value D[m,j] */
currDist += bool(HP & horizontal_mask);
currDist -= bool(HN & horizontal_mask);
horizontal_mask >>= 1;

/* Step 4: Computing Vp and VN */
VP = HN | ~((D0 >> 1) | HP);
Expand Down

0 comments on commit d937555

Please sign in to comment.