Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Erlang's implementation of jaro distance, fix bugs #13369

Merged
merged 2 commits into from
Feb 26, 2024

Conversation

sabiwara
Copy link
Contributor

Close #13349

Copies the implementation of erlang/otp#7879

@sabiwara sabiwara marked this pull request as draft February 25, 2024 23:13
Comment on lines 3073 to 3074
# TODO: Remove me when we require Erlang/OTP 27+
@jaro_module if :erlang.system_info(:otp_release) >= [?2, ?7], do: :string, else: :elixir_utils
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't sure: is it enough to check the OTP version at compile time, or is there another preferred way?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can just always call the one in elixir_utils for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense!

@@ -999,6 +999,7 @@ defmodule StringTest do
assert String.jaro_distance("jon", "john") == 0.9166666666666666
assert String.jaro_distance("jon", "jan") == 0.7777777777777777
assert String.jaro_distance("семена", "стремя") == 0.6666666666666666
assert String.jaro_distance("Sunday", "Saturday") == 0.7194444444444444
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Adding the example mentioned here

Comment on lines +3069 to 3071
def jaro_distance(string, string) when is_binary(string), do: 1.0
def jaro_distance(_string, ""), do: 0.0
def jaro_distance("", _string), do: 0.0
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt we could keep these optimizations since they weren't in the Erlang version, WDYT?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to keep them, yeah. :)

@sabiwara sabiwara marked this pull request as ready for review February 25, 2024 23:23
@sabiwara sabiwara merged commit 3c55db7 into elixir-lang:main Feb 26, 2024
8 checks passed
@sabiwara sabiwara deleted the jaro branch February 26, 2024 10:25
@sabiwara
Copy link
Contributor Author

@josevalim should I backport this one since it's a bug? Or not because of the vendored thing?

@josevalim
Copy link
Member

Let's not backport this one, it seems a bit larger for a patch release and the bug has been there for several versions anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Fix bug in jaro_distance implementation
2 participants