Skip to content

[RFC]: Hamming distance between two strings #836

Open

Description

@Planeshifter

Description

This RFC proposes adding a function to calculate the Hamming distance between two strings.

The function should have the following signature (a: string, b: string): number.

The function should take two strings as arguments and return the Hamming distance between them. The Hamming distance is defined as the number of characters that have to be changed to convert one string to the other. Since it only allows substitutions, it can only be used to compare strings of the same length.

Additionally, in order to account for code points and grapheme clusters, we should add separate packages for dealing with each, as the underlying algorithms are likely to differ. We then can provide a more general API which unifies the underlying algorithms. Accordingly, we should create the following packages:

  • @stdlib/string/base/distances/hamming: compares UTF-16 code units.
  • @stdlib/string/base/distances/hamming-code-points: compares Unicode code points.
  • @stdlib/string/base/distances/hamming-grapheme-clusters: compares grapheme clusters (i.e., visual characters)

Once the above are completed, we can add

  • @stdlib/string/distances/hamming: unifies the above "base" packages and provides an option for specifying the computation "mode" (i.e., code_units, code_points, or grapheme_clusters, with grapheme_clusters being the default).

Related Issues

Related issues #151.

Questions

No.

Other

No.

Checklist

  • I have read and understood the Code of Conduct.
  • Searched for existing issues and pull requests.
  • The issue name begins with RFC:.

Activity

  1. added
    RFCRequest for comments. Feature requests and proposed changes.
    FeatureIssue or pull request for adding a new feature.
    Good First IssueA good first issue for new contributors!
    on Feb 1, 2023
  2. Ahtaxam commented on Apr 30, 2023

    @Ahtaxam
  3. kgryte commented on Jul 15, 2023

    @kgryte
  4. added
    difficulty: 3Likely to be challenging but manageable.
    priority: LowLow priority concern or feature request.
    UtilitiesIssue or pull request concerning general utilities.
    AcceptedRFC feature request which has been accepted.
    JavaScriptIssue involves or relates to JavaScript.
    on Feb 23, 2024
  5. marsian83 commented on Feb 29, 2024

    @marsian83
    Contributor

    Hi, I would like to work on this
    Can I be assgined this

  6. kgryte commented on Feb 29, 2024

    @kgryte
    Member

    @marsian83 Sure. Would you be open to working on @stdlib/string/base/distances/hamming-code-points?

  7. kgryte commented on Feb 29, 2024

    @kgryte
    Member

    Note that the UTF-16 code unit implementation has already been added. The code points implementation should iterate over Unicode code points (e.g., most Unicode characters and some emoji). You can find other code points implementation in the string/base/* namespace.

  8. marsian83 commented on Mar 1, 2024

    @marsian83
    Contributor

    Note that the UTF-16 code unit implementation has already been added. The code points implementation should iterate over Unicode code points (e.g., most Unicode characters and some emoji). You can find other code points implementation in the string/base/* namespace.

    Sure, I'll see how these work.
    Thanks for the reference

  9. mayankkamboj47 commented on Mar 2, 2024

    @mayankkamboj47

    @kgryte Hello ! Can I work on the grapheme clusters part ?

  10. kgryte commented on Mar 2, 2024

    @kgryte
    Member

    @mayankkamboj47 Sure. You'll probably want to rely on next-grapheme-cluster-break in order to derive string indices for the purpose of comparing substrings.

  11. Pratik772846 commented on Mar 5, 2024

    @Pratik772846
    Contributor

    @kgryte @Planeshifter If noone is working on @stdlib/string/base/distances/hamming-code-points, can i work on it?

  12. JayPokale commented on Mar 19, 2024

    @JayPokale

    @kgryte I created a pull request for Hamming distance between Unicode characters (#1948 ). Can you please review it.
    Looking forward for your reply.

  13. JayPokale commented on Mar 27, 2024

    @JayPokale

    Hello there, can someone please review PR #1948 on @stdlib/string/base/distances/hamming-code-points.

  14. MynameisSanskar commented on Nov 8, 2024

    @MynameisSanskar

    Hi @kgryte,

    I am interested in contributing to the Hamming distance feature for comparing Unicode code points in the @stdlib/string/base/distances/hamming-code-points package. Could you please assign this task to me?

    Looking forward to your guidance and feedback!

    Thank you!``

  15. Anant1004 commented on Nov 10, 2024

    @Anant1004

    Hello, everyone ! I'm interested in contributing to the Hamming distance feature. I noticed that parts of the implementation for different comparison modes (UTF-16 code units, Unicode code points, and grapheme clusters) have been discussed and some PRs have been submitted. Could someone please update me on the current status of this issue and let me know if there are any open tasks I could help with? Thank you !

  16. kgryte commented on Nov 18, 2024

    @kgryte
    Member

    @MynameisSanskar @Anant1004 As tracked in the OP, calculating the distance between two strings when comparing code points has not been completed. Initial attempt to add support can be found in #1948, but that PR stalled.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AcceptedRFC feature request which has been accepted.FeatureIssue or pull request for adding a new feature.Good First IssueA good first issue for new contributors!JavaScriptIssue involves or relates to JavaScript.RFCRequest for comments. Feature requests and proposed changes.UtilitiesIssue or pull request concerning general utilities.difficulty: 3Likely to be challenging but manageable.priority: LowLow priority concern or feature request.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions