Skip to content

Commit 1d36c75

Browse files
authored
FSharp.Core: Map: fix tracing (#10191)
#if-protected tracing was not updated properly in #10188 Also synchronize with Set: tolerance and mk max height calculation
1 parent 77687e3 commit 1d36c75

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/fsharp/FSharp.Core/map.fs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ module MapTree =
6666
(totalSizeOnMapLookup / float numLookups))
6767
System.Console.WriteLine("#largestMapSize = {0}, largestMapStackTrace = {1}", largestMapSize, largestMapStackTrace)
6868

69-
let MapOne n =
69+
let MapTree n =
7070
report()
7171
numOnes <- numOnes + 1
7272
totalSizeOnNodeCreation <- totalSizeOnNodeCreation + 1.0
7373
MapTree n
7474

75-
let MapNode (x, l, v, r, h) =
75+
let MapTreeNode (x, l, v, r, h) =
7676
report()
7777
numNodes <- numNodes + 1
7878
let n = MapTreeNode (x, l, v, r, h)
@@ -87,10 +87,13 @@ module MapTree =
8787
| :? MapTreeNode<'Key, 'Value> as mn -> mn.Height
8888
| _ -> 1
8989

90+
[<Literal>]
91+
let tolerance = 2
92+
9093
let mk l k v r : MapTree<'Key, 'Value> =
9194
let hl = height l
9295
let hr = height r
93-
let m = max hl hr
96+
let m = if hl < hr then hr else hl
9497
if m = 0 then // m=0 ~ isEmpty l && isEmpty r
9598
MapTree(k,v)
9699
else
@@ -102,7 +105,7 @@ module MapTree =
102105
let rebalance t1 (k: 'Key) (v: 'Value) t2 : MapTree<'Key, 'Value> =
103106
let t1h = height t1
104107
let t2h = height t2
105-
if t2h > t1h + 2 then (* right is heavier than left *)
108+
if t2h > t1h + tolerance then (* right is heavier than left *)
106109
let t2' = asNode(t2)
107110
(* one of the nodes must have height > height t1 + 1 *)
108111
if height t2'.Left > t1h + 1 then (* balance left: combination *)
@@ -111,7 +114,7 @@ module MapTree =
111114
else (* rotate left *)
112115
mk (mk t1 k v t2'.Left) t2'.Key t2'.Value t2'.Right
113116
else
114-
if t1h > t2h + 2 then (* left is heavier than right *)
117+
if t1h > t2h + tolerance then (* left is heavier than right *)
115118
let t1' = asNode(t1)
116119
(* one of the nodes must have height > height t2 + 1 *)
117120
if height t1'.Right > t2h + 1 then
@@ -461,7 +464,7 @@ module MapTree =
461464
let current i =
462465
if i.started then
463466
match i.stack with
464-
| [] -> alreadyFinished()
467+
| [] -> alreadyFinished()
465468
| m :: _ ->
466469
match m with
467470
| :? MapTreeNode<'Key, 'Value> -> failwith "Please report error: Map iterator, unexpected stack for current"

0 commit comments

Comments
 (0)