@@ -41,69 +41,98 @@ module internal HashImplementation =
4141 open HashNumberCrunching
4242
4343 [<AllowNullLiteral>]
44- type SetLinked < 'K > =
45- val mutable public SetNext : SetLinked < 'K >
46- val mutable public Key : 'K
47- new ( k, n) = { Key = k; SetNext = n }
48-
44+ type SetLinked < 'K >( key : 'K , next : SetLinked < 'K >) =
45+ let mutable key = key
46+ let mutable next = next
47+
48+ member x.Key
49+ with inline get() = key
50+ and inline set v = key <- v
51+
52+ member x.SetNext
53+ with inline get() = next
54+ and inline set v = next <- v
55+
4956 [<AllowNullLiteral>]
50- type MapLinked < 'K , 'V > =
51- inherit SetLinked< 'K>
52- val mutable public Value : 'V
57+ type MapLinked < 'K , 'V >( key : 'K , value : 'V , next : MapLinked < 'K , 'V >) =
58+ inherit SetLinked< 'K>( key, next :> SetLinked< 'K>)
59+ let mutable value = value
60+
61+ member x.Value
62+ with inline get() = value
63+ and inline set v = value <- v
5364
5465 member x.MapNext
5566 with inline get() : MapLinked< 'K, 'V> = downcast x.SetNext
5667 and inline set ( v : MapLinked < 'K , 'V >) = x.SetNext <- v
5768
58- new ( k : 'K, v : 'V, n : MapLinked< 'K, 'V>) = { inherit SetLinked< 'K>( k, n :> SetLinked < 'K >); Value = v }
59-
6069 type NodeKind =
6170 | Leaf = 0 uy
6271 | Inner = 1 uy
6372
6473 [<AllowNullLiteral; AbstractClass>]
65- type SetNode < 'K > =
66- val mutable public Store : uint32
67-
74+ type SetNode < 'K >( k : NodeKind , data : uint32 ) =
75+ let mutable store = ( data <<< 1 ) ||| uint32 k
76+
6877 member inline x.IsLeaf =
69- x.Store &&& 1 u = 0 u
78+ store &&& 1 u = 0 u
7079
7180 member x.Data
72- with inline get() = x.Store >>> 1
73- and inline set v = x.Store <- ( v <<< 1 ) ||| ( x.Store &&& 1 u)
81+ with inline get() = store >>> 1
82+ and inline set v = store <- ( v <<< 1 ) ||| ( store &&& 1 u)
7483
75- new ( k : NodeKind, data : uint32) = { Store = ( data <<< 1 ) ||| uint32 k }
84+ type SetLeaf < 'K >( hash : uint32 , key : 'K , next : SetLinked < 'K >) =
85+ inherit SetNode< 'K>( NodeKind.Leaf, hash)
86+ let mutable key = key
87+ let mutable next = next
7688
77- type SetLeaf < 'K > =
78- inherit SetNode< 'K>
79- val mutable public Key : 'K
80- val mutable public SetNext : SetLinked < 'K >
89+ member x.Key
90+ with inline get() = key
91+ and inline set v = key <- v
92+
93+ member x.SetNext
94+ with inline get() = next
95+ and inline set v = next <- v
8196
8297 member x.Hash
8398 with inline get() = x.Data
8499 and inline set v = x.Data <- v
85100
86- new ( hash : uint32, key : 'K, next : SetLinked< 'K>) =
87- { inherit SetNode< 'K>( NodeKind.Leaf, hash); Key = key; SetNext = next }
101+ type MapLeaf < 'K , 'V >( hash : uint32 , key : 'K , value : 'V , next : MapLinked < 'K , 'V >) =
102+ inherit SetLeaf< 'K>( hash, key, next)
103+ let mutable value = value
88104
89- type MapLeaf < 'K , 'V > =
90- inherit SetLeaf < 'K >
91- val mutable public Value : 'V
105+ member x.Value
106+ with inline get () = value
107+ and inline set v = value <- v
92108
93109 member x.MapNext
94110 with inline get() : MapLinked< 'K, 'V> = downcast x.SetNext
95111 and inline set ( v : MapLinked < 'K , 'V >) = x.SetNext <- v
96112
97- new ( hash : uint32, key : 'K, value : 'V, next : MapLinked< 'K, 'V>) =
98- { inherit SetLeaf< 'K>( hash, key, next); Value = value }
113+ type Inner < 'K >( prefix : uint32 , mask : uint32 , left : SetNode < 'K >, right : SetNode < 'K >) =
114+ inherit SetNode< 'K>( NodeKind.Inner, prefix)
115+ let mutable mask = mask
116+ let mutable count = Inner.GetCount left + Inner.GetCount right
117+ let mutable left = left
118+ let mutable right = right
119+
120+ member x.Mask
121+ with inline get() = mask
122+ and inline set v = mask <- v
123+
124+ member x.Count
125+ with inline get() = count
126+ and inline set v = count <- v
127+
128+ member x.Left
129+ with inline get() = left
130+ and inline set v = left <- v
131+
132+ member x.Right
133+ with inline get() = right
134+ and inline set v = right <- v
99135
100- type Inner < 'K > =
101- inherit SetNode< 'K>
102- val mutable public Mask : uint32
103- val mutable public Count : int
104- val mutable public Left : SetNode < 'K >
105- val mutable public Right : SetNode < 'K >
106-
107136 static member GetCount ( node : SetNode < 'K >) =
108137 if isNull node then 0
109138 elif node.IsLeaf then
@@ -119,15 +148,11 @@ module internal HashImplementation =
119148 else
120149 let inner = node :?> Inner< 'K>
121150 inner.Count
122-
123151
124152 member x.Prefix
125153 with inline get() = x.Data
126154 and inline set v = x.Data <- v
127155
128- new ( prefix : uint32, mask : uint32, left : SetNode< 'K>, right : SetNode< 'K>) =
129- let cnt = Inner.GetCount left + Inner.GetCount right
130- { inherit SetNode< 'K>( NodeKind.Inner, prefix); Mask = mask; Count = cnt; Left = left; Right = right }
131156
132157 let size ( node : SetNode < 'K >) =
133158 Inner.GetCount node
0 commit comments