Skip to content

Commit 26d4878

Browse files
authored
Merge pull request #85 from ncave/fable
Fixed Fable issue
2 parents 431120e + ce1bedd commit 26d4878

2 files changed

Lines changed: 100 additions & 54 deletions

File tree

src/FSharp.Data.Adaptive/Datastructures/HashCollections.fs

Lines changed: 64 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -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 = 0uy
6271
| Inner = 1uy
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 &&& 1u = 0u
78+
store &&& 1u = 0u
7079

7180
member x.Data
72-
with inline get() = x.Store >>> 1
73-
and inline set v = x.Store <- (v <<< 1) ||| (x.Store &&& 1u)
81+
with inline get() = store >>> 1
82+
and inline set v = store <- (v <<< 1) ||| (store &&& 1u)
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

src/FSharp.Data.Adaptive/Datastructures/MapExt.fs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,20 +37,44 @@ module internal MapExtImplementation =
3737
uint32 a ^^^ uint32 b + 0x9e3779b9u + ((uint32 a) <<< 6) + ((uint32 a) >>> 2) |> int
3838

3939
[<AllowNullLiteral; NoEquality; NoComparison>]
40-
type Node<'Key, 'Value> =
41-
val mutable public Height : byte
42-
val mutable public Key : 'Key
43-
val mutable public Value : 'Value
44-
new(k, v, h) = { Key = k; Value = v; Height = h }
45-
new(k, v) = { Key = k; Value = v; Height = 1uy }
40+
type Node<'Key, 'Value>(key : 'Key, value : 'Value, height : byte) =
41+
let mutable height = height
42+
let mutable key = key
43+
let mutable value = value
44+
45+
member x.Key
46+
with inline get() = key
47+
and inline set v = key <- v
48+
49+
member x.Value
50+
with inline get() = value
51+
and inline set v = value <- v
52+
53+
member x.Height
54+
with inline get() = height
55+
and inline set v = height <- v
56+
57+
new(k, v) = Node<'Key, 'Value>(k, v, 1uy)
4658

4759
[<Sealed; AllowNullLiteral; NoEquality; NoComparison>]
48-
type Inner<'Key, 'Value> =
49-
inherit Node<'Key, 'Value>
50-
val mutable public Count : int
51-
val mutable public Left : Node<'Key, 'Value>
52-
val mutable public Right : Node<'Key, 'Value>
53-
60+
type Inner<'Key, 'Value>(l : Node<'Key, 'Value>, k : 'Key, v : 'Value, r : Node<'Key, 'Value>, h : byte, cnt : int) =
61+
inherit Node<'Key, 'Value>(k, v, h)
62+
let mutable left = l
63+
let mutable right = r
64+
let mutable count = cnt
65+
66+
member x.Left
67+
with inline get() = left
68+
and inline set v = left <- v
69+
70+
member x.Right
71+
with inline get() = right
72+
and inline set v = right <- v
73+
74+
member x.Count
75+
with inline get() = count
76+
and inline set v = count <- v
77+
5478
static member inline GetCount(node : Node<'Key, 'Value>) =
5579
if isNull node then 0
5680
elif node.Height = 1uy then 1
@@ -68,9 +92,6 @@ module internal MapExtImplementation =
6892
inner.Count <- 1 + lc + rc
6993
inner.Height <- 1uy + max lh rh
7094

71-
new(l : Node<'Key, 'Value>, k : 'Key, v : 'Value, r : Node<'Key, 'Value>, h : byte, cnt : int) =
72-
{ inherit Node<'Key, 'Value>(k, v, h); Left = l; Right = r; Count = cnt }
73-
7495
static member Create(l : Node<'Key, 'Value>, k : 'Key, v : 'Value, r : Node<'Key, 'Value>) =
7596
if isNull l && isNull r then Node(k, v)
7697
else

0 commit comments

Comments
 (0)