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

refactor: mergeSingleChildTrees #180

Closed
wants to merge 1 commit into from
Closed

refactor: mergeSingleChildTrees #180

wants to merge 1 commit into from

Conversation

Mintnoii
Copy link

@Mintnoii Mintnoii commented Dec 5, 2023

TODO solved: try to make it without recursion, but still typesafe

Advantages of the iterative approach with a stack:

  • Avoiding potential stack overflow: Using an explicit stack allows you to control and manage the memory usage more efficiently, reducing the risk of a stack overflow, especially for deep trees.

  • Improved performance: Iterative approaches often have better performance characteristics compared to recursive solutions, as they avoid the overhead of function calls and stack management.

I hope this is helpful for you, and I look forward to your review. :)

} else {
return node;
const leaf: ModuleTreeLeaf = { name, uid: child.uid };
return leaf;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one not correct. We modify tree in place. But this branch will cut it completly


while (stack.length > 0) {
const current = stack.pop();

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add if(!current) break, instead of repeating it in both conditions

@btd
Copy link
Owner

btd commented Dec 9, 2023

This seems not correct to me. I do not remember if there are unit tests for this. But i suggest to add them first to check that your implementation does not change behaviour

@Mintnoii Mintnoii closed this Dec 11, 2023
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