From 433f78edcbb8f2fc5be7e49c82a86ad657d0202f 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:27 +0000 Subject: [PATCH 1/2] Initial plan From 48f38a44bd52979041f8c504a0085b111948a7c9 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 30 Jul 2025 15:40:02 +0000 Subject: [PATCH 2/2] Add time and space complexity documentation to all public functions in Map module Co-authored-by: T-Gro <46543583+T-Gro@users.noreply.github.com> --- src/FSharp.Core/map.fsi | 43 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/src/FSharp.Core/map.fsi b/src/FSharp.Core/map.fsi index 2fdabdbb29f..e6b9b2d3b21 100644 --- a/src/FSharp.Core/map.fsi +++ b/src/FSharp.Core/map.fsi @@ -19,6 +19,7 @@ type Map<[] 'Key, [Returns a new map with the binding added to the given map. /// If a binding with the given key already exists in the input map, the existing binding is replaced by the new binding in the result map. + /// Time complexity: O(log n), Space complexity: O(log n) /// The key to add. /// The value to add. /// @@ -35,6 +36,7 @@ type Map<[] 'Key, [ Map<'Key, 'Value> /// Returns a new map with the value stored under key changed according to f. + /// Time complexity: O(log n), Space complexity: O(log n) /// /// The input key. /// The change function. @@ -56,6 +58,7 @@ type Map<[] 'Key, [ 'Value option) -> Map<'Key, 'Value> /// Returns true if there are no bindings in the map. + /// Time complexity: O(1), Space complexity: O(1) /// /// /// @@ -69,6 +72,7 @@ type Map<[] 'Key, [Builds a map that contains the bindings of the given IEnumerable. + /// Time complexity: O(n log n), Space complexity: O(n) /// /// The input sequence of key/value pairs. /// @@ -82,6 +86,7 @@ type Map<[] 'Key, [ -> Map<'Key, 'Value> /// Tests if an element is in the domain of the map. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// @@ -98,6 +103,7 @@ type Map<[] 'Key, [ bool /// The number of bindings in the map. + /// Time complexity: O(n), Space complexity: O(1) /// /// /// @@ -110,6 +116,7 @@ type Map<[] 'Key, [Lookup an element in the map. Raise KeyNotFoundException if no binding /// exists in the map. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// Thrown when the key is not found. @@ -127,6 +134,7 @@ type Map<[] 'Key, [ 'Value with get /// Removes an element from the domain of the map. No exception is raised if the element is not present. + /// Time complexity: O(log n), Space complexity: O(log n) /// /// The input key. /// @@ -144,6 +152,7 @@ type Map<[] 'Key, [Lookup an element in the map, returning a Some value if the element is in the domain /// of the map and None if not. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// @@ -161,6 +170,7 @@ type Map<[] 'Key, [Lookup an element in the map, assigning to value if the element is in the domain /// of the map and returning false if not. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// A reference to the output value. @@ -185,6 +195,7 @@ type Map<[] 'Key, [The keys in the map. /// The sequence will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// /// @@ -197,6 +208,7 @@ type Map<[] 'Key, [All the values in the map, including the duplicates. /// The sequence will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// /// @@ -223,6 +235,7 @@ module Map = /// Returns a new map with the binding added to the given map. /// If a binding with the given key already exists in the input map, the existing binding is replaced by the new binding in the result map. + /// Time complexity: O(log n), Space complexity: O(log n) /// /// The input key. /// The input value. @@ -242,6 +255,7 @@ module Map = val add: key: 'Key -> value: 'T -> table: Map<'Key, 'T> -> Map<'Key, 'T> /// Returns a new map with the value stored under key changed according to f. + /// Time complexity: O(log n), Space complexity: O(log n) /// /// The input key. /// The change function. @@ -264,6 +278,7 @@ module Map = val change: key: 'Key -> f: ('T option -> 'T option) -> table: Map<'Key, 'T> -> Map<'Key, 'T> /// Returns a new map made from the given bindings. + /// Time complexity: O(n log n), Space complexity: O(n) /// /// The input list of key/value pairs. /// @@ -280,6 +295,7 @@ module Map = val ofList: elements: ('Key * 'T) list -> Map<'Key, 'T> /// Returns a new map made from the given bindings. + /// Time complexity: O(n log n), Space complexity: O(n) /// /// The input array of key/value pairs. /// @@ -296,6 +312,7 @@ module Map = val ofArray: elements: ('Key * 'T) array -> Map<'Key, 'T> /// Returns a new map made from the given bindings. + /// Time complexity: O(n log n), Space complexity: O(n) /// /// The input sequence of key/value pairs. /// @@ -313,6 +330,7 @@ module Map = /// Views the collection as an enumerable sequence of pairs. /// The sequence will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// The input map. /// @@ -330,6 +348,7 @@ module Map = /// Returns a list of all key-value pairs in the mapping. /// The list will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// The input map. /// @@ -347,6 +366,7 @@ module Map = /// Returns an array of all key-value pairs in the mapping. /// The array will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// The input map. /// @@ -363,6 +383,7 @@ module Map = val toArray: table: Map<'Key, 'T> -> ('Key * 'T) array /// Is the map empty? + /// Time complexity: O(1), Space complexity: O(1) /// /// The input map. /// @@ -381,6 +402,7 @@ module Map = val isEmpty: table: Map<'Key, 'T> -> bool /// The empty map. + /// Time complexity: O(1), Space complexity: O(1) /// /// /// @@ -393,6 +415,7 @@ module Map = /// Lookup an element in the map, raising KeyNotFoundException if no binding /// exists in the map. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// The input map. @@ -412,6 +435,7 @@ module Map = val find: key: 'Key -> table: Map<'Key, 'T> -> 'T /// Searches the map looking for the first element where the given function returns a Some value. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to generate options from the key/value pairs. /// The input map. @@ -440,6 +464,7 @@ module Map = /// Searches the map looking for the first element where the given function returns a Some value. /// Raise KeyNotFoundException if no such element exists. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to generate options from the key/value pairs. /// The input map. @@ -468,6 +493,7 @@ module Map = val pick: chooser: ('Key -> 'T -> 'U option) -> table: Map<'Key, 'T> -> 'U /// Folds over the bindings in the map. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to update the state given the input key/value pairs. /// The input map. @@ -489,6 +515,7 @@ module Map = when 'Key: comparison /// Folds over the bindings in the map + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to update the state given the input key/value pairs. /// The initial state. @@ -510,6 +537,7 @@ module Map = when 'Key: comparison /// Applies the given function to each binding in the dictionary + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to apply to each key/value pair. /// The input map. @@ -527,6 +555,7 @@ module Map = /// Returns true if the given predicate returns true for one of the /// bindings in the map. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to test the input elements. /// The input map. @@ -545,6 +574,7 @@ module Map = val exists: predicate: ('Key -> 'T -> bool) -> table: Map<'Key, 'T> -> bool /// Builds a new map containing only the bindings for which the given predicate returns 'true'. + /// Time complexity: O(n log n), Space complexity: O(n) /// /// The function to test the key/value pairs. /// The input map. @@ -563,6 +593,7 @@ module Map = /// Returns true if the given predicate returns true for all of the /// bindings in the map. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to test the input elements. /// The input map. @@ -583,6 +614,7 @@ module Map = /// Builds a new collection whose elements are the results of applying the given function /// to each of the elements of the collection. The key passed to the /// function indicates the key of element being transformed. + /// Time complexity: O(n), Space complexity: O(n) /// /// The function to transform the key/value pairs. /// The input map. @@ -600,6 +632,7 @@ module Map = val map: mapping: ('Key -> 'T -> 'U) -> table: Map<'Key, 'T> -> Map<'Key, 'U> /// Tests if an element is in the domain of the map. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// The input map. @@ -619,6 +652,7 @@ module Map = /// Builds two new maps, one containing the bindings for which the given predicate returns 'true', /// and the other the remaining bindings. + /// Time complexity: O(n log n), Space complexity: O(n) /// /// The function to test the input elements. /// The input map. @@ -637,6 +671,7 @@ module Map = val partition: predicate: ('Key -> 'T -> bool) -> table: Map<'Key, 'T> -> Map<'Key, 'T> * Map<'Key, 'T> /// Removes an element from the domain of the map. No exception is raised if the element is not present. + /// Time complexity: O(log n), Space complexity: O(log n) /// /// The input key. /// The input map. @@ -656,6 +691,7 @@ module Map = /// Lookup an element in the map, returning a Some value if the element is in the domain /// of the map and None if not. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input key. /// The input map. @@ -675,6 +711,7 @@ module Map = /// Evaluates the function on each mapping in the collection. Returns the key for the first mapping /// where the function returns 'true'. Raise KeyNotFoundException if no such element exists. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to test the input elements. /// The input map. @@ -695,6 +732,7 @@ module Map = /// Returns the key of the first mapping in the collection that satisfies the given predicate. /// Returns 'None' if no such element exists. + /// Time complexity: O(n), Space complexity: O(log n) /// /// The function to test the input elements. /// The input map. @@ -713,6 +751,7 @@ module Map = val tryFindKey: predicate: ('Key -> 'T -> bool) -> table: Map<'Key, 'T> -> 'Key option /// The number of bindings in the map. + /// Time complexity: O(n), Space complexity: O(1) /// /// /// @@ -726,6 +765,7 @@ module Map = /// The keys in the map. /// The sequence will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// /// @@ -739,6 +779,7 @@ module Map = /// The values in the map, including the duplicates. /// The sequence will be ordered by the keys of the map. + /// Time complexity: O(n), Space complexity: O(n) /// /// /// @@ -752,6 +793,7 @@ module Map = /// Returns binding for the smallest key in the map. /// Raise KeyNotFoundException when map is empty. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input map. /// Thrown if the map is empty. @@ -768,6 +810,7 @@ module Map = /// Returns binding for the largest key in the map. /// Raise KeyNotFoundException when map is empty. + /// Time complexity: O(log n), Space complexity: O(1) /// /// The input map. /// Thrown if the map is empty.