Skip to content

Improve XCTAssertUnorderedEqualSequences complexity to O(n) for Hashable elements - #285

Open
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:fix/unordered-equal-hashable-complexity
Open

Improve XCTAssertUnorderedEqualSequences complexity to O(n) for Hashable elements#285
shubhransh-gupta wants to merge 1 commit into
apple:mainfrom
shubhransh-gupta:fix/unordered-equal-hashable-complexity

Conversation

@shubhransh-gupta

Copy link
Copy Markdown

Description

Resolves #176.

Improves the algorithmic complexity of expectUnorderedEqualSequences from $O(n^2)$ to $O(n)$ when sequence elements conform to Hashable, by tracking counts with a frequency dictionary instead of sequential firstIndex(of:) removals from an Array.

Detailed Design

  • Added a generic overload of expectUnorderedEqualSequences constrained to S1.Element: Hashable.
  • Retained the existing S1.Element: Equatable implementation as a fallback for types that only conform to Equatable.

Checklist

  • I've added at least one test that validates that my change is working, if appropriate
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XCTAssertUnorderedEqualSequences: Improve algorithmic complexity when elements are Hashable

1 participant