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

perf: Avoid sorting and deduplicating in Node.flatten #31

Merged
merged 1 commit into from
Mar 10, 2023

Conversation

Pscheidl
Copy link
Contributor

With Vec in place, flattening takes a merge sort, which is O(n*log(n)). Then, an additional pass to deduplicate O(n) is required. This can be avoided by using a HashSet, which is guaranteed to be O(1) on insert. Also, a HashSet doesn't need any intermediate memory allocations.

With `Vec` in place, flattening takes a merge sort, which is `O(n*log(n))`.
Then, an additional pass to deduplicate O(n) is required. This can be avoided
by using a HashSet, which is guaranteed to be O(1) on insert. Also,
a HashSet doesn't need any intermediate memory allocations.
@Xuanwo
Copy link
Owner

Xuanwo commented Mar 10, 2023

Great!

@Xuanwo Xuanwo merged commit 66ee8b1 into Xuanwo:main Mar 10, 2023
@Pscheidl Pscheidl deleted the flatten-avoid-sorting branch March 10, 2023 09:14
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.

2 participants