-
Notifications
You must be signed in to change notification settings - Fork 0
[feat] add CopyMapSubset #11
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #11 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 3 3
Lines 172 187 +15
=========================================
+ Hits 172 187 +15 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR introduces a new function CopyMapSubset for creating a subset of a map and also optimizes map pre-allocation in existing functions.
- Optimizes the ToSet and CopyMap functions by pre-allocating map capacity.
- Adds extensive test coverage for the new CopyMapSubset function.
- Introduces the CopyMapSubset function with pre-allocation improvements.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| set.go | Pre-allocates map capacity in the ToSet function. |
| map_test.go | Adds tests for the new CopyMapSubset function covering various scenarios. |
| map.go | Pre-allocates slices/maps in multiple functions and adds CopyMapSubset; contains a redundant nil check in Merge. |
2b5f1d3 to
9b3979a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request introduces a new CopyMapSubset function for creating map subsets based on specified keys while also optimizing map creation in several helper functions. Key changes include:
- Pre-allocating map capacity in ToSet and CopyMap for improved performance.
- Adding CopyMapSubset and corresponding tests covering various edge cases.
- Refining EqualKeys and Merge to improve clarity and safety in map operations.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| set.go | Optimized map allocation in ToSet by pre-allocating capacity using len(slice). |
| map_test.go | Added comprehensive tests for CopyMapSubset across multiple scenarios. |
| map.go | Added CopyMapSubset, improved CopyMap with pre-allocation, refactored EqualKeys, and updated Merge to return a copy when input map a is nil. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds a new function, CopyMapSubset, to create a subset of a map using specified keys while also optimizing map creation by pre-allocating map capacities.
- Introduces CopyMapSubset in map.go along with relevant documentation.
- Adds comprehensive tests for CopyMapSubset in map_test.go.
- Optimizes map pre-allocation in ToSet and CopyMap functions in set.go and map.go.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| set.go | Optimizes ToSet by pre-allocating the map capacity. |
| map_test.go | Adds tests for the new CopyMapSubset function. |
| map.go | Adds CopyMapSubset and optimizes map pre-allocation in CopyMap and Merge. |
|
|
||
| // MissingKeys returns the keys that are in a but not b | ||
| func MissingKeys[K comparable, V any](a, b map[K]V) []K { | ||
| // Pre-allocate with capacity of a since that's the maximum possible size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why so pessimistic? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment was written by Claude 3.7 Sonnet. I think it's correct though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but if a has 100 keys and b has all of them, you're building a map with capacity 100 to store nothing.
Also: optimize map creation