Skip to content

Improve SortedSet union #2267

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bobzhang
Copy link
Contributor

Summary

  • optimize union in SortedSet
  • avoid re-counting elements by tracking size during tree copy/merge

Testing

  • moon fmt
  • moon info
  • moon test

https://chatgpt.com/codex/tasks/task_e_684bd59b9ccc8320b5e9a44429fe1b2b

Copy link

Avoid duplicated tree copying in union operation

Category
Performance
Code Snippet
let (t1, _) = copy_tree_with_size(self.root)
let (t2, _) = copy_tree_with_size(src.root)
Recommendation
The size information from copy_tree_with_size is discarded but could be useful. Consider using it to initialize the base size before merging.
Reasoning
The initial size information could provide a better starting point for size tracking and potentially avoid some computations during the merge process.

Missing documentation for copy_tree_with_size function

Category
Maintainability
Code Snippet
fn[V] copy_tree_with_size(node : Node[V]?) -> (Node[V]?, Int)
Recommendation
Add detailed documentation explaining the purpose, parameters and return values using the ///| format as seen in other functions.
Reasoning
Consistent documentation helps maintainability and makes the codebase more approachable for new developers.

Potential integer overflow risk in size calculations

Category
Correctness
Code Snippet
(Some(new_node), lsize + rsize + 1)
Recommendation
Consider adding size overflow checks when adding node counts, or document the maximum supported set size.
Reasoning
The recursive addition of sizes could potentially overflow for very large sets, leading to incorrect size tracking.

@coveralls
Copy link
Collaborator

Pull Request Test Coverage Report for Build 7263

Details

  • 16 of 16 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.005%) to 93.115%

Totals Coverage Status
Change from base Build 7259: 0.005%
Covered Lines: 8575
Relevant Lines: 9209

💛 - Coveralls

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

Successfully merging this pull request may close these issues.

2 participants