From d0cd43155c6e95c2114ea8acabfbf5fd12718e95 Mon Sep 17 00:00:00 2001 From: Christian Luksch Date: Thu, 12 Sep 2024 23:46:20 +0200 Subject: [PATCH] changed IndexMapping to use value options --- .../AdaptiveIndexList/AdaptiveIndexList.fs | 28 +++++++++---------- .../CollectionExtensions.fs | 4 +-- .../Utilities/Utilities.fs | 26 ++++++++--------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/FSharp.Data.Adaptive/AdaptiveIndexList/AdaptiveIndexList.fs b/src/FSharp.Data.Adaptive/AdaptiveIndexList/AdaptiveIndexList.fs index 3cc7372..724213f 100644 --- a/src/FSharp.Data.Adaptive/AdaptiveIndexList/AdaptiveIndexList.fs +++ b/src/FSharp.Data.Adaptive/AdaptiveIndexList/AdaptiveIndexList.fs @@ -792,8 +792,8 @@ module internal AdaptiveIndexListImplementation = |> MapExt.toSeq |> Seq.choose (fun (ii, v) -> match mapping.Revoke(oi,ii) with - | Some v -> Some (v, Remove) - | None -> None + | ValueSome v -> Some (v, Remove) + | ValueNone -> None ) |> IndexListDelta.ofSeq @@ -826,8 +826,8 @@ module internal AdaptiveIndexListImplementation = targets |> Seq.choose (fun oi -> match mapping.Revoke(oi, ii) with - | Some i -> Some(i, Remove) - | None -> None + | ValueSome i -> Some(i, Remove) + | ValueNone -> None ) |> IndexListDelta.ofSeq @@ -936,9 +936,9 @@ module internal AdaptiveIndexListImplementation = | Remove -> let outIndex = mapping.Revoke(index, i) match outIndex with - | Some outIndex -> + | ValueSome outIndex -> Some (outIndex, Remove) - | None -> + | ValueNone -> None ) @@ -1024,8 +1024,8 @@ module internal AdaptiveIndexListImplementation = match cache.TryGetValue i with | (true, b) -> match idx.Revoke((b, i)) with - | Some oi -> Some (oi, Remove) - | None -> None + | ValueSome oi -> Some (oi, Remove) + | ValueNone -> None | _ -> None let b = mapping i v @@ -1039,8 +1039,8 @@ module internal AdaptiveIndexListImplementation = | (true, b) -> cache.Remove i |> ignore match idx.Revoke((b, i)) with - | Some oi -> [(oi, Remove)] - | None -> [] + | ValueSome oi -> [(oi, Remove)] + | ValueNone -> [] | _ -> [] ) @@ -1073,8 +1073,8 @@ module internal AdaptiveIndexListImplementation = match MapExt.tryFind i old with | Some ov -> match idx.Revoke(UCmp(cmp, struct(ov, i))) with - | Some oi -> Some (oi, Remove) - | None -> None + | ValueSome oi -> Some (oi, Remove) + | ValueNone -> None | _ -> None let oi = idx.Invoke(UCmp(cmp, struct(v, i))) @@ -1085,8 +1085,8 @@ module internal AdaptiveIndexListImplementation = match MapExt.tryFind i old with | Some ov -> match idx.Revoke(UCmp(cmp, struct(ov, i))) with - | Some oi -> [(oi, Remove)] - | None -> [] + | ValueSome oi -> [(oi, Remove)] + | ValueNone -> [] | _ -> [] ) diff --git a/src/FSharp.Data.Adaptive/CollectionExtensions.fs b/src/FSharp.Data.Adaptive/CollectionExtensions.fs index d634727..c348049 100644 --- a/src/FSharp.Data.Adaptive/CollectionExtensions.fs +++ b/src/FSharp.Data.Adaptive/CollectionExtensions.fs @@ -54,8 +54,8 @@ module CollectionExtensions = | Rem(_, v) -> let k = cache.Revoke v match mapping.Revoke k with - | Some idx -> Some (idx, Remove) - | None -> None + | ValueSome idx -> Some (idx, Remove) + | ValueNone -> None ) |> IndexListDelta.ofSeq diff --git a/src/FSharp.Data.Adaptive/Utilities/Utilities.fs b/src/FSharp.Data.Adaptive/Utilities/Utilities.fs index aa35888..be4b41d 100644 --- a/src/FSharp.Data.Adaptive/Utilities/Utilities.fs +++ b/src/FSharp.Data.Adaptive/Utilities/Utilities.fs @@ -176,28 +176,28 @@ module internal AdaptiveIndexListHelpers = member x.Invoke(k : 'k) = let mutable index = Index.zero - let inline ret i = index <- i; Some i + let inline ret i = index <- i; ValueSome i let newStore = - store |> MapExt.changeWithNeighbours k (fun left self right -> + store |> MapExt.changeWithNeighboursV k (fun left self right -> match self with - | Some i -> ret i - | None -> + | ValueSome i -> ret i + | ValueNone -> match left, right with - | None, None -> Index.after Index.zero |> ret - | Some(_,l), None -> Index.after l |> ret - | None, Some(_,r) -> Index.before r |> ret - | Some (_,l), Some(_,r) -> Index.between l r |> ret + | ValueNone, ValueNone -> Index.after Index.zero |> ret + | ValueSome(_,l), ValueNone -> Index.after l |> ret + | ValueNone, ValueSome(_,r) -> Index.before r |> ret + | ValueSome (_,l), ValueSome(_,r) -> Index.between l r |> ret ) store <- newStore index member x.Revoke(k : 'k) = - match MapExt.tryRemove k store with - | Some(i, rest) -> + match MapExt.tryRemoveV k store with + | ValueSome(i, rest) -> store <- rest - Some i - | None -> - None + ValueSome i + | ValueNone -> + ValueNone member x.Clear() = store <- MapExt.empty