From cd7835617a86068d76de3badaec0f94c44307094 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 15:08:47 +0000 Subject: [PATCH 1/4] Initial plan From 7cd023a06cc0970dda71d0082a0c1417f1fa8960 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 15:38:58 +0000 Subject: [PATCH 2/4] Add time and space complexity documentation to core collection operators Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- src/FSharp.Core/array.fsi | 10 +++++++++- src/FSharp.Core/list.fsi | 10 +++++++++- src/FSharp.Core/prim-types.fsi | 4 ++++ src/FSharp.Core/set.fsi | 4 ++++ 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/FSharp.Core/array.fsi b/src/FSharp.Core/array.fsi index 18a4463277e..0ae2be5c515 100644 --- a/src/FSharp.Core/array.fsi +++ b/src/FSharp.Core/array.fsi @@ -46,6 +46,8 @@ module Array = /// /// Thrown when either of the input arrays is null. /// + /// Time complexity: O(n + m) where n and m are the lengths of the input arrays. Space complexity: O(n + m). + /// /// /// /// Array.append [| 1; 2 |] [| 3; 4 |] @@ -278,6 +280,8 @@ module Array = /// /// Thrown when the input sequence is null. /// + /// Time complexity: O(n) where n is the total number of elements in all arrays. Space complexity: O(n). + /// /// /// /// let inputs = [ [| 1; 2 |]; [| 3 |]; [| 4; 5 |] ] @@ -1234,6 +1238,8 @@ module Array = /// Thrown when the input array is null. /// Thrown when the input array is empty. /// + /// Time complexity: O(1). Space complexity: O(1). + /// /// /// /// let inputs = [| "banana"; "pear" |] @@ -1530,7 +1536,7 @@ module Array = /// /// The length of the array. /// - /// The notation array.Length is preferred. + /// Time complexity: O(1). Space complexity: O(1). The notation array.Length is preferred. /// /// Thrown when the input array is null. /// @@ -2582,6 +2588,8 @@ module Array = /// /// A new array containing the elements of the original except the first element. /// + /// Time complexity: O(n) where n is the length of the array. Space complexity: O(n). + /// /// /// /// let inputs = [| "a"; "bb"; "ccc" |] diff --git a/src/FSharp.Core/list.fsi b/src/FSharp.Core/list.fsi index c77e26ddaf0..42d0ad9d079 100644 --- a/src/FSharp.Core/list.fsi +++ b/src/FSharp.Core/list.fsi @@ -46,6 +46,8 @@ module List = /// /// The resulting list. /// + /// Time complexity: O(n) where n is the length of the first list. Space complexity: O(n). + /// /// /// /// List.append [ 1..3 ] [ 4..7 ] @@ -345,6 +347,8 @@ module List = /// /// The resulting concatenated list. /// + /// Time complexity: O(n) where n is the total number of elements in all lists. Space complexity: O(n). + /// /// /// /// let input = [ [1;2] @@ -1013,6 +1017,8 @@ module List = /// /// The first element of the list. /// + /// Time complexity: O(1). Space complexity: O(1). + /// /// /// /// let inputs = ["banana"; "pear"] @@ -1251,7 +1257,7 @@ module List = /// /// The length of the list. /// - /// The notation array.Length is preferred. + /// Time complexity: O(n) where n is the length of the list. Space complexity: O(1). The notation array.Length is preferred. /// /// /// @@ -2088,6 +2094,8 @@ module List = /// /// The list after removing the first element. /// + /// Time complexity: O(1). Space complexity: O(1). + /// /// /// /// let inputs = ["a"; "bb"; "ccc"] diff --git a/src/FSharp.Core/prim-types.fsi b/src/FSharp.Core/prim-types.fsi index 6697e108d2c..b755328f0c5 100644 --- a/src/FSharp.Core/prim-types.fsi +++ b/src/FSharp.Core/prim-types.fsi @@ -2674,6 +2674,8 @@ namespace Microsoft.FSharp.Collections [] type List<'T> = | ([]): 'T list + /// Cons operator for adding an element to the front of a list. + /// Time complexity: O(1). Space complexity: O(1). | (::): Head: 'T * Tail: 'T list -> 'T list /// Returns an empty list of a particular type @@ -3800,6 +3802,8 @@ namespace Microsoft.FSharp.Core /// /// The concatenation of the lists. /// + /// Time complexity: O(n) where n is the length of the first list. Space complexity: O(n). + /// /// /// /// let l1 = ['a'; 'b'; 'c'] diff --git a/src/FSharp.Core/set.fsi b/src/FSharp.Core/set.fsi index d60432fcd0b..6a6267318e0 100644 --- a/src/FSharp.Core/set.fsi +++ b/src/FSharp.Core/set.fsi @@ -297,6 +297,8 @@ module Set = /// /// A new set containing value. /// + /// Time complexity: O(log n) where n is the size of the set. Space complexity: O(log n) due to path copying in the balanced tree. + /// /// /// /// let set = Set.empty.Add(1).Add(1).Add(2) @@ -680,6 +682,8 @@ module Set = /// /// The input set with value removed. /// + /// Time complexity: O(log n) where n is the size of the set. Space complexity: O(log n) due to path copying in the balanced tree. + /// /// /// /// let set = Set.empty.Add(1).Add(2).Add(3) From 157bbf8cbd3e6751c705e3f104cc8376c43a7559 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 15:46:34 +0000 Subject: [PATCH 3/4] Complete time and space complexity documentation for collection operators Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- src/FSharp.Core/map.fsi | 4 ++++ src/FSharp.Core/seq.fsi | 4 +++- src/FSharp.Core/set.fsi | 4 ++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/FSharp.Core/map.fsi b/src/FSharp.Core/map.fsi index 2fdabdbb29f..911161f778a 100644 --- a/src/FSharp.Core/map.fsi +++ b/src/FSharp.Core/map.fsi @@ -230,6 +230,8 @@ module Map = /// /// The resulting map. /// + /// Time complexity: O(log n) where n is the size of the map. Space complexity: O(log n) due to path copying in the balanced tree. + /// /// /// /// let input = Map [ (1, "a"); (2, "b") ] @@ -643,6 +645,8 @@ module Map = /// /// The resulting map. /// + /// Time complexity: O(log n) where n is the size of the map. Space complexity: O(log n) due to path copying in the balanced tree. + /// /// /// /// let sample = Map [ (1, "a"); (2, "b") ] diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi index 24189d3730c..5d51023286c 100644 --- a/src/FSharp.Core/seq.fsi +++ b/src/FSharp.Core/seq.fsi @@ -38,7 +38,9 @@ module Seq = /// /// The returned sequence may be passed between threads safely. However, /// individual IEnumerator values generated from the returned sequence should not be accessed - /// concurrently. + /// concurrently. + /// + /// Time complexity: O(1) - sequences are lazily evaluated. Space complexity: O(1). /// /// The first sequence. /// The second sequence. diff --git a/src/FSharp.Core/set.fsi b/src/FSharp.Core/set.fsi index 6a6267318e0..5a9920514a2 100644 --- a/src/FSharp.Core/set.fsi +++ b/src/FSharp.Core/set.fsi @@ -541,6 +541,8 @@ module Set = /// /// The intersection of set1 and set2. /// + /// Time complexity: O(n + m) where n and m are the sizes of the input sets. Space complexity: O(min(n, m)). + /// /// /// /// let set1 = Set.empty.Add(1).Add(2).Add(3) @@ -584,6 +586,8 @@ module Set = /// /// The union of set1 and set2. /// + /// Time complexity: O(n + m) where n and m are the sizes of the input sets. Space complexity: O(n + m). + /// /// /// /// let set1 = Set.empty.Add(1).Add(2).Add(3) From 8c49a0978445de7b52e750f11dcafd07996c35a0 Mon Sep 17 00:00:00 2001 From: GH Actions Date: Thu, 31 Jul 2025 08:49:01 +0000 Subject: [PATCH 4/4] Apply patch from /run fantomas --- src/FSharp.Core/seq.fsi | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/FSharp.Core/seq.fsi b/src/FSharp.Core/seq.fsi index 5d51023286c..fd5e59c616f 100644 --- a/src/FSharp.Core/seq.fsi +++ b/src/FSharp.Core/seq.fsi @@ -39,7 +39,7 @@ module Seq = /// The returned sequence may be passed between threads safely. However, /// individual IEnumerator values generated from the returned sequence should not be accessed /// concurrently. - /// + /// /// Time complexity: O(1) - sequences are lazily evaluated. Space complexity: O(1). /// /// The first sequence.