@@ -7,6 +7,11 @@ module DifferentiationExtensions =
77 /// Functional programming operators related to the HashSet<_ > type.
88 module HashSet =
99
10+ /// Determines the operations needed to transform l into r, using custom element operation functions.
11+ /// Returns a HashSetDelta containing these operations.
12+ let computeDeltaCustom ( l : HashSet < 'T >) ( r : HashSet < 'T >) ( add : 'T -> bool ) ( remove : 'T -> bool ) =
13+ l.ComputeDeltaAsHashMap( r, remove, add) |> HashSetDelta
14+
1015 /// Determines the operations needed to transform l into r.
1116 /// Returns a HashSetDelta containing these operations.
1217 let computeDelta ( l : HashSet < 'T >) ( r : HashSet < 'T >) =
@@ -43,15 +48,13 @@ module DifferentiationExtensions =
4348 /// Functional programming operators related to the HashMap<_ ,_ > type.
4449 module HashMap =
4550
46- /// Determines the operations needed to transform l into r.
51+ /// Determines the operations needed to transform l into r, using custom element operation functions .
4752 /// Returns a HashMapDelta containing all the needed operations.
48- let computeDelta ( l : HashMap < 'A , 'B >) ( r : HashMap < 'A , 'B >): HashMapDelta < 'A , 'B > =
49- let inline add ( _k : 'A ) ( v : 'B ) = ValueSome ( Set v)
50- let inline remove ( _k : 'A ) ( v : 'B ) = ValueSome Remove
51- let inline update ( _k : 'A ) ( o : 'B ) ( n : 'B ) =
52- if DefaultEquality.equals o n then ValueNone
53- else ValueSome ( Set n)
54-
53+ let computeDeltaCustom
54+ ( add : 'A -> 'B -> ValueOption < ElementOperation < 'B >>)
55+ ( remove : 'A -> 'B -> ValueOption < ElementOperation < 'B >>)
56+ ( update : 'A -> 'B -> 'B -> ValueOption < ElementOperation < 'B >>)
57+ ( l : HashMap < 'A , 'B >) ( r : HashMap < 'A , 'B >): HashMapDelta < 'A , 'B > =
5558 let delta =
5659 HashImplementation.MapNode.computeDelta
5760 l.Comparer
@@ -63,6 +66,16 @@ module DifferentiationExtensions =
6366
6467 HashMap< 'A, ElementOperation< 'B>>( l.Comparer, delta) |> HashMapDelta
6568
69+ /// Determines the operations needed to transform l into r.
70+ /// Returns a HashMapDelta containing all the needed operations.
71+ let computeDelta ( l : HashMap < 'A , 'B >) ( r : HashMap < 'A , 'B >): HashMapDelta < 'A , 'B > =
72+ let inline add ( _k : 'A ) ( v : 'B ) = ValueSome ( Set v)
73+ let inline remove ( _k : 'A ) ( v : 'B ) = ValueSome Remove
74+ let inline update ( _k : 'A ) ( o : 'B ) ( n : 'B ) =
75+ if DefaultEquality.equals o n then ValueNone
76+ else ValueSome ( Set n)
77+ computeDeltaCustom add remove update l r
78+
6679 let applyDelta ( l : HashMap < 'K , 'V >) ( r : HashMapDelta < 'K , 'V >) =
6780 let inline apply ( _ : 'K ) ( o : voption < 'V >) ( n : ElementOperation < 'V >) =
6881 match n with
@@ -90,8 +103,8 @@ module DifferentiationExtensions =
90103 /// Functional programming operators related to the IndexList<_ > type.
91104 module IndexList =
92105
93- /// Determines the operations needed to transform l into r.
94- /// Returns a IndexListDelta containing these operations.
106+ /// Applies the given operations to the list.
107+ /// Returns the new list and the 'effective' operations.
95108 let applyDelta ( x : IndexList < 'T >) ( deltas : IndexListDelta < 'T >) =
96109 let inline apply _ o n =
97110 match n with
@@ -108,14 +121,23 @@ module DifferentiationExtensions =
108121 struct ( ValueSome v, ValueSome ( Set v))
109122 let s , d = x.Content.ApplyDeltaAndGetEffective( deltas.Content, apply)
110123 IndexList.ofMap s, IndexListDelta.ofMap d
111-
112- /// Applies the given operations to the list.
124+
125+ /// Applies the given operations to the list, using custom element operation functions .
113126 /// Returns the new list and the 'effective' operations.
127+ let computeDeltaCustom
128+ ( add : Index -> 'T -> ElementOperation < 'T >)
129+ ( remove : Index -> 'T -> ElementOperation < 'T >)
130+ ( update : Index -> 'T -> 'T -> ValueOption < ElementOperation < 'T >>)
131+ ( l : IndexList < 'T >) ( r : IndexList < 'T >) : IndexListDelta < 'T > =
132+ let res = l.Content.ComputeDeltaTo( r.Content, add, update, remove)
133+ IndexListDelta res
134+
135+ /// Determines the operations needed to transform l into r.
136+ /// Returns a IndexListDelta containing these operations.
114137 let computeDelta ( l : IndexList < 'T >) ( r : IndexList < 'T >) : IndexListDelta < 'T > =
115138 let inline add _ v = Set v
116139 let inline rem _ _ = Remove
117140 let inline update _ o n =
118141 if DefaultEquality.equals o n then ValueNone
119142 else ValueSome ( Set n)
120- let res = l.Content.ComputeDeltaTo( r.Content, add, update, rem)
121- IndexListDelta res
143+ computeDeltaCustom add rem update l r
0 commit comments