Skip to content

Commit

Permalink
changed IndexMapping to use value options
Browse files Browse the repository at this point in the history
  • Loading branch information
luithefirst committed Sep 12, 2024
1 parent ae61ada commit d0cd431
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 29 deletions.
28 changes: 14 additions & 14 deletions src/FSharp.Data.Adaptive/AdaptiveIndexList/AdaptiveIndexList.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
)

Expand Down Expand Up @@ -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
Expand All @@ -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 -> []
| _ ->
[]
)
Expand Down Expand Up @@ -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)))
Expand All @@ -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 -> []
| _ ->
[]
)
Expand Down
4 changes: 2 additions & 2 deletions src/FSharp.Data.Adaptive/CollectionExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 13 additions & 13 deletions src/FSharp.Data.Adaptive/Utilities/Utilities.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit d0cd431

Please sign in to comment.