Skip to content

Commit ef107e9

Browse files
committed
fixed KeyNotFoundException in async evaluation of ASet.mapA and flattenA computations (#103)
1 parent a2f0c4a commit ef107e9

2 files changed

Lines changed: 21 additions & 20 deletions

File tree

RELEASE_NOTES.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
### 1.2.12
2+
* fixed KeyNotFoundException in async evaluation of `ASet.mapA` and `ASet.flattenA` (issue #103)
3+
14
### 1.2.11
25
* fixed `AList.sub` problem
36

src/FSharp.Data.Adaptive/AdaptiveHashSet/AdaptiveHashSet.fs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -918,12 +918,6 @@ module AdaptiveHashSetImplementation =
918918
cache.[m] <- v
919919
v
920920

921-
member x.Invoke2(token : AdaptiveToken, m : aval<'T>) =
922-
let o = cache.[m]
923-
let v = m.GetValue token
924-
cache.[m] <- v
925-
o, v
926-
927921
member x.Revoke(m : aval<'T>, dirty : System.Collections.Generic.HashSet<_>) =
928922
match cache.TryGetValue m with
929923
| (true, v) ->
@@ -944,9 +938,14 @@ module AdaptiveHashSetImplementation =
944938
)
945939

946940
for d in dirty do
947-
let o, n = x.Invoke2(token, d)
948-
if not (DefaultEquality.equals o n) then
949-
deltas <- HashSetDelta.combine deltas (HashSetDelta.ofList [Add n; Rem o])
941+
match cache.TryGetValue d with
942+
| (true, o) ->
943+
let n = d.GetValue token
944+
cache.[d] <- n
945+
if not (DefaultEquality.equals o n) then
946+
deltas <- HashSetDelta.combine deltas (HashSetDelta.ofArray [| Add n; Rem o |])
947+
| _ -> ()
948+
950949

951950
deltas
952951

@@ -970,15 +969,8 @@ module AdaptiveHashSetImplementation =
970969
| _ ->
971970
let r = ref (1, v)
972971
cache.[m] <- r
973-
974972
v
975973

976-
member x.Invoke2(token : AdaptiveToken, m : aval<'B>) =
977-
let r = cache.[m]
978-
let v = m.GetValue token
979-
let (rc, o) = r.Value
980-
r.Value <- (rc, v)
981-
o, v
982974

983975
member x.Revoke(v : 'A, dirty : System.Collections.Generic.HashSet<_>) =
984976
let m = mapping.Revoke v
@@ -1007,9 +999,15 @@ module AdaptiveHashSetImplementation =
1007999
)
10081000

10091001
for d in dirty do
1010-
let o, n = x.Invoke2(token, d)
1011-
if not (DefaultEquality.equals o n) then
1012-
deltas <- HashSetDelta.combine deltas (HashSetDelta.ofList [Add n; Rem o])
1002+
match cache.TryGetValue d with
1003+
| (true, r) ->
1004+
let n = d.GetValue token
1005+
let (rc, o) = r.Value
1006+
r.Value <- (rc, n)
1007+
if not (DefaultEquality.equals o n) then
1008+
deltas <- HashSetDelta.combine deltas (HashSetDelta.ofArray [| Add n; Rem o |])
1009+
| _ -> ()
1010+
10131011

10141012
deltas
10151013

@@ -1210,7 +1208,7 @@ module ASet =
12101208
else constant (fun () -> HashSet.union va vb)
12111209
else
12121210
// TODO: can be optimized in case one of the two sets is constant.
1213-
ofReader (fun () -> UnionConstantReader (HashSet.ofList [a;b]))
1211+
ofReader (fun () -> UnionConstantReader (HashSet.ofArray [| a; b |]))
12141212

12151213
/// Adaptively subtracts the given sets.
12161214
let difference (a : aset<'A>) (b : aset<'A>) =

0 commit comments

Comments
 (0)