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

XCTAssertUnorderedEqualSequences: Improve algorithmic complexity when elements are Hashable #176

Open
mdznr opened this issue Dec 14, 2021 · 1 comment · May be fixed by #177
Open

XCTAssertUnorderedEqualSequences: Improve algorithmic complexity when elements are Hashable #176

mdznr opened this issue Dec 14, 2021 · 1 comment · May be fixed by #177

Comments

@mdznr
Copy link
Contributor

mdznr commented Dec 14, 2021

In the (only) implementation of XCTAssertUnorderedEqualSequences (where elements are Equatable), it converts the sequence into an Array. Then it iterates through the second sequence, calling firstIndex(of:) on the first array (O(n)), which totals to O(n2). If a Set were used (when the elements are Hashable), then getting the index of an element is O(1), which would make the total algorithmic complexity O(n).

Expected behavior

XCTAssertUnorderedEqualSequences is O(n) when Element: Hashable

Actual behavior

XCTAssertUnorderedEqualSequences is O(n2) when Element: Hashable

@mdznr
Copy link
Contributor Author

mdznr commented Dec 21, 2021

Introduced with commit ca8af77

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