-
Notifications
You must be signed in to change notification settings - Fork 824
Add time and space complexity documentation to Seq module functions #18796
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
base: main
Are you sure you want to change the base?
Conversation
…nd, average, averageBy, cache, cast, choose) Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…llect, compareWith, concat, contains) Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
… distinct, distinctBy, splitInto, empty, except) Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
…, exists2, filter, where, find) Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com>
/run fantomas |
🔧 CLI Command Report
✅ Patch applied: |
Fantomas formatting applied successfully. Removed trailing whitespace from one line in the complexity documentation. |
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 comprehensive time and space complexity documentation to the F# Seq module public functions. The documentation provides developers with crucial performance guidance by deriving complexities from actual implementation patterns.
Key changes:
- Added time and space complexity annotations to 24 core Seq module functions
- Used strict, consistent format with "Time Complexity" and "Space Complexity" remarks
- Integrated documentation into existing remarks sections where present
/// <remarks>Remember sequence is lazy, effects are delayed until it is enumerated.</remarks> | ||
/// <remarks>Remember sequence is lazy, effects are delayed until it is enumerated. | ||
/// | ||
/// Time Complexity: O(1) - for lazy sequence construction, O(n + Σk_i) for full enumeration where k_i is the length of each mapped subsequence |
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 complexity notation 'Σk_i' may be unclear to some developers. Consider using more explicit notation like 'sum of lengths of all subsequences' or 'total elements across all mapped subsequences' for better readability.
/// Time Complexity: O(1) - for lazy sequence construction, O(n + Σk_i) for full enumeration where k_i is the length of each mapped subsequence | |
/// Time Complexity: O(1) - for lazy sequence construction, O(n + s) for full enumeration, where n is the number of elements in the input sequence and s is the sum of the lengths of all mapped subsequences |
Copilot uses AI. Check for mistakes.
/// individual IEnumerator values generated from the returned sequence should not be accessed concurrently.</remarks> | ||
/// individual IEnumerator values generated from the returned sequence should not be accessed concurrently. | ||
/// | ||
/// Time Complexity: O(1) - for lazy sequence construction, O(Σn_i) for full enumeration where n_i is the length of each subsequence |
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.
Similar to the collect function, the complexity notation 'Σn_i' may be unclear. Consider using more explicit notation like 'sum of lengths of all subsequences' for consistency and clarity.
/// Time Complexity: O(1) - for lazy sequence construction, O(Σn_i) for full enumeration where n_i is the length of each subsequence | |
/// Time Complexity: O(1) - for lazy sequence construction, O(sum of lengths of all subsequences) for full enumeration |
Copilot uses AI. Check for mistakes.
This PR adds comprehensive time and space complexity documentation to public functions in the
Seq
module inseq.fsi
. The documentation derives complexities from the actual implementation patterns and provides developers with crucial performance guidance.What was added
Added time and space complexity annotations to 24 core Seq module functions using a strict, consistent format:
Functions documented
The complexity documentation covers key functional programming operations including:
allPairs
- O(n*m) time, O(m) spaceappend
,concat
- O(1) lazy construction, linear enumerationaverage
,averageBy
- O(n) time, O(1) spacecache
- O(k) space where k is elements accessedchoose
,filter
,where
- O(1) lazy, O(n) enumerationchunkBySize
,splitInto
- Various patterns based on materializationcollect
- O(n + Σk_i) for nested sequencescompareWith
,contains
- Early termination patternsdistinct
,distinctBy
- O(n) time, O(k) space for unique elementsexists
,exists2
- Short-circuiting evaluationfind
- O(n) worst case with early terminationexcept
- O(n+m) with hash-based exclusionImplementation approach
seq.fs
implementation patternsExample improvements
Before:
After:
This documentation helps developers make informed decisions about performance-critical code paths and understand the computational costs of different sequence operations.
Validation
seq.fs
This pull request was created as a result of the following prompt from Copilot chat.
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.