Skip to content

Commit cb4bfe4

Browse files
T-Groactions-user
andauthored
Fsharp.Core - adding time complexity to collection functions (#19240)
* Add time/space complexity remarks to Set type and module functions - Added complexity documentation to all 47 Set functions/members - Set type members: new O(n log n), Add/Remove/Contains O(log n), Count/IsEmpty O(1), Min/MaximumElement O(log n), set operations O(m log n), subset/superset O(n log m) - Set module functions: empty/singleton/isEmpty O(1), add/remove/contains O(log n), fold/iter/exists/forall O(n), filter/map/partition O(n log n), union/intersect/difference O(m log n), ofList/ofArray/ofSeq O(n log n), toList/toArray O(n), toSeq O(1) - Format: '<remarks>This is an O(...) operation, where n is...</remarks>' - Build succeeds with 0 errors - XML validation test passes * Add complexity documentation to Map module (~43 functions) Added <remarks> with O(n) complexity documentation to all public Map type members and module functions in map.fsi: Type members (12): Add, Change, IsEmpty, new, ContainsKey, Count, Item, Remove, TryFind, TryGetValue, Keys, Values Module functions (31): empty, isEmpty, add, change, find, tryFind, remove, containsKey, iter, tryPick, pick, exists, filter, partition, forall, map, fold, foldBack, toSeq, toList, toArray, findKey, tryFindKey, ofList, ofSeq, ofArray, count, keys, values, minKeyValue, maxKeyValue All remarks use consistent prose style following the pattern: 'Maps are represented as binary trees so this is an O(log n) operation' Build: dotnet build src/FSharp.Core/FSharp.Core.fsproj -c Release - 0 errors Tests: XmlDocumentationValidation - 1 passed * Add complexity documentation for @ operator in prim-types.fsi - Add O(n) complexity remarks for the @ (append) operator Sprint 1 DoD: - Build: ✅ 0 errors - XML tests: ✅ Passed - Map.fsi: ✅ 44 remarks - @ operator: ✅ Documented - No duplicates: ✅ Verified * Add complexity documentation to List module (~100 functions) - Add <remarks> with O() complexity info to all public List module functions - Append complexity to existing remarks where applicable - Follow prose format: 'This is an O(n) operation...' - Lists are represented as linked lists - O(1) for head/tail, O(n) for indexing * Add complexity documentation to Array and Seq modules (~224 functions) Array module: 132 complexity remarks added - O(1) for length, get, set, head, last, isEmpty, item, toSeq, singleton - O(n) for most iteration/mapping operations - O(n log n) for sorting operations - O(n*m) for allPairs, transpose - O(min(n,m)) for compareWith Seq module: 92 complexity remarks added - Lazy construction O(1) with O(n) enumeration for most operations - O(n) for immediate operations like fold, iter, length - O(n log n) for sorting - O(k) space for distinct operations where k is unique elements * Add complexity remarks to all random* functions in List module Added O(n) complexity documentation to 12 random* functions: - randomShuffle, randomShuffleWith, randomShuffleBy: O(n) - randomChoice, randomChoiceWith, randomChoiceBy: O(n) - randomChoices, randomChoicesWith, randomChoicesBy: O(n * count) - randomSample, randomSampleWith, randomSampleBy: O(n) All 117 List module functions now have complexity remarks. Build and XML validation tests pass. * Add complexity documentation to all 164 Array module functions - Fixed 43 duplicate <remarks> tags by merging complexity into existing remarks - Added missing complexity remarks to 33 functions including all random* functions - Fixed misplaced remark for Array.empty (between attributes) - All 164 val declarations now have O(...) complexity in <remarks> - Build: 0 warnings, 0 errors - XmlDocumentationValidation test: 1 passed, 0 failed * Add complexity remarks to Seq random* functions Added O(n) complexity documentation to 12 random* functions in seq.fsi: - randomShuffle, randomShuffleWith, randomShuffleBy - randomChoice, randomChoiceWith, randomChoiceBy - randomChoices, randomChoicesWith, randomChoicesBy - randomSample, randomSampleWith, randomSampleBy All functions have O(n) complexity because they first materialize the sequence to an array before performing random operations. Build: 0 errors XmlDocumentationValidation: 1 passed, 0 failed * Fix duplicate remarks tags in Seq module documentation Merged 41 duplicate <remarks> tags where complexity remarks were added separately from existing behavioral remarks. Each function now has at most one <remarks> section containing both behavioral documentation and complexity information. - Build: 0 errors - XmlDocumentationValidation test: 1 passed - 107 remarks covering 118 val declarations - No duplicate remarks tags per function - Format correctly distinguishes lazy construction vs enumeration cost * Add complexity remarks to remaining 11 Seq functions Complete coverage: 118/118 functions now have complexity remarks Added remarks for: - indexed: Sequence construction is O(1), Enumeration is O(n) - length: O(n) eager operation - ofList: O(1) view operation - replicate: O(1) construction, O(count) enumeration - scanBack: O(n) eager, consumes whole sequence - toArray: O(n) eager materialization - removeAt: O(n) where n is the index - updateAt: O(n) where n is the index - insertManyAt: O(n) where n is the index - average: O(n) eager operation - contains: O(n) eager operation Build: 0 errors, 0 warnings XmlDocumentationValidation test: PASSED * Fix duplicate <remarks> tags in Seq.average and Seq.scanBack - Remove duplicate complexity remarks from average function - Merge duplicate remarks content into single tag for scanBack function - Verified: Build passes with 0 errors, XmlDocumentationValidation test passes * Add missing complexity remarks to delay, empty, nth, and sum in seq.fsi - delay: O(1) construction, enumeration cost depends on generated sequence - empty: O(1) operation - nth: O(n) where n is the index - sum: O(n) where n is the length of the sequence This completes 100% coverage: 118/118 Seq functions now have complexity remarks. * Add complexity remarks to list Cons operator in prim-types.fsi - Added O(1) complexity remark to static member Cons (:: operator) Complexity documentation summary: - set.fsi: 47 remarks - map.fsi: 43 remarks - list.fsi: 117 remarks - array.fsi: 164 remarks - seq.fsi: 118 remarks - prim-types.fsi: 3 remarks (Item, Cons, @) Total: 492 complexity remarks across 6 files * update * Update 10.0.200.md * Apply patch from /run fantomas --------- Co-authored-by: GH Actions <actions@github.com>
1 parent e196266 commit cb4bfe4

File tree

13 files changed

+905
-108
lines changed

13 files changed

+905
-108
lines changed

docs/release-notes/.FSharp.Core/10.0.300.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@
44

55
### Changed
66

7+
* Added complexity documentation (Big-O notation) to all 462 functions across Array, List, Seq, Map, and Set collection modules. ([PR #19240](https://github.com/dotnet/fsharp/pull/19240))
8+
79
### Breaking Changes

0 commit comments

Comments
 (0)