Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

IsAnagram bug (per element counts) #153

Open
@ZacharyPatten

Description

@ZacharyPatten

Describe the bug

TheIsAnagram function is not checking per-element counts. It is only checking if they have the same elements, but not if the count of each element matches.

A more appropriate name for the current logic is something likeContainsNoDifferingElements orIntersectsMatch rather thanIsAnagram. I would recommend changing the name or the logic of the method.

Note: If you aren't going to check per-element counts, then you should also get rid of this check inIsAnagrams:

if(source.Length!=other.Length)returnfalse;

because length doesn't matter if you don't also check per-element counts.

To Reproduce

Add the following case to theIsAnagram unit tests:

stringaab="aab";stringabb="abb";Assert.False(Permutations.IsAnargram(aab,abb));

Expected behavior

Spans of the same length and elements but different per-element counts should not be considered re-orders/anagrams of each other.

Environment:

master branch

Additional context

I have written my own version of this algorithm in C#(that fixes this issue) if interested here...

Source Code:https://github.com/ZacharyPatten/Towel/blob/d2660e208ad3a44ab22f192834760c5b93dc82ac/Sources/Towel/Statics-SequenceAnalysis.cs#L1321
Examples:https://github.com/ZacharyPatten/Towel/blob/d2660e208ad3a44ab22f192834760c5b93dc82ac/Examples/BasicsAndExtensions/Program.cs#L406
Testing:https://github.com/ZacharyPatten/Towel/blob/d2660e208ad3a44ab22f192834760c5b93dc82ac/Tools/Towel_Testing/Statics.cs#L2086
Note:MapHashLinked is my version of aDictionary if you look at the source code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp