Skip to content

Commit 26e3374

Browse files
authored
Merge pull request #39 from lasp-lang/delta-inflations
Allow deltas to be used in inflation checking.
2 parents 14eddcf + 483f8c1 commit 26e3374

12 files changed

+131
-25
lines changed

src/state_bcounter.erl

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,9 @@ equal({?TYPE, {PNCounter1, GMap1}}, {?TYPE, {PNCounter2, GMap2}}) ->
189189
%% @doc Given two `state_bcounter()', check if the second is an
190190
%% inflation of the first.
191191
%% We have and inflation if we have an inflation component wise.
192-
-spec is_inflation(state_bcounter(), state_bcounter()) -> boolean().
192+
-spec is_inflation(delta_or_state(), state_bcounter()) -> boolean().
193+
is_inflation({?TYPE, {delta, BCounter1}}, {?TYPE, BCounter2}) ->
194+
is_inflation({?TYPE, BCounter1}, {?TYPE, BCounter2});
193195
is_inflation({?TYPE, {PNCounter1, GMap1}}, {?TYPE, {PNCounter2, GMap2}}) ->
194196
?PNCOUNTER_TYPE:is_inflation(PNCounter1, PNCounter2) andalso
195197
?GMAP_TYPE:is_inflation(GMap1, GMap2).
@@ -202,7 +204,9 @@ is_inflation({?TYPE, {PNCounter1, GMap1}}, {?TYPE, {PNCounter2, GMap2}}) ->
202204
%% Composition of State-based CRDTs (2015)
203205
%% [http://haslab.uminho.pt/cbm/files/crdtcompositionreport.pdf]
204206
%%
205-
-spec is_strict_inflation(state_bcounter(), state_bcounter()) -> boolean().
207+
-spec is_strict_inflation(delta_or_state(), state_bcounter()) -> boolean().
208+
is_strict_inflation({?TYPE, {delta, BCounter1}}, {?TYPE, BCounter2}) ->
209+
is_strict_inflation({?TYPE, BCounter1}, {?TYPE, BCounter2});
206210
is_strict_inflation({?TYPE, {PNCounter1, GMap1}}, {?TYPE, {PNCounter2, GMap2}}) ->
207211
(?PNCOUNTER_TYPE:is_strict_inflation(PNCounter1, PNCounter2)
208212
andalso

src/state_gcounter.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,9 @@ equal({?TYPE, GCounter1}, {?TYPE, GCounter2}) ->
142142
%% - the value for each replica in the first `state_gcounter()'
143143
%% should be less or equal than the value for the same
144144
%% replica in the second `state_gcounter()'
145-
-spec is_inflation(state_gcounter(), state_gcounter()) -> boolean().
145+
-spec is_inflation(delta_or_state(), state_gcounter()) -> boolean().
146+
is_inflation({?TYPE, {delta, GCounter1}}, {?TYPE, GCounter2}) ->
147+
is_inflation({?TYPE, GCounter1}, {?TYPE, GCounter2});
146148
is_inflation({?TYPE, GCounter1}, {?TYPE, GCounter2}) ->
147149
lists_ext:iterate_until(
148150
fun({Key, Value1}) ->
@@ -163,7 +165,9 @@ is_inflation({value, Value1}, {?TYPE, _}=GCounter) ->
163165
Value2 >= Value1.
164166

165167
%% @doc Check for strict inflation.
166-
-spec is_strict_inflation(state_gcounter(), state_gcounter()) -> boolean().
168+
-spec is_strict_inflation(delta_or_state(), state_gcounter()) -> boolean().
169+
is_strict_inflation({?TYPE, {delta, GCounter1}}, {?TYPE, GCounter2}) ->
170+
is_strict_inflation({?TYPE, GCounter1}, {?TYPE, GCounter2});
167171
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
168172
state_type:is_strict_inflation(CRDT1, CRDT2);
169173

@@ -273,11 +277,14 @@ equal_test() ->
273277

274278
is_inflation_test() ->
275279
Counter1 = {?TYPE, [{1, 2}, {2, 1}, {4, 1}]},
280+
DeltaCounter1 = {?TYPE, {delta, [{1, 2}, {2, 1}, {4, 1}]}},
276281
Counter2 = {?TYPE, [{1, 2}, {2, 1}, {4, 1}, {5, 6}]},
277282
Counter3 = {?TYPE, [{1, 2}, {2, 2}, {4, 1}]},
278283
Counter4 = {?TYPE, [{1, 2}, {2, 1}]},
279284
?assert(is_inflation(Counter1, Counter1)),
280285
?assert(is_inflation(Counter1, Counter2)),
286+
?assert(is_inflation(DeltaCounter1, Counter1)),
287+
?assert(is_inflation(DeltaCounter1, Counter2)),
281288
?assert(is_inflation(Counter1, Counter3)),
282289
?assertNot(is_inflation(Counter1, Counter4)),
283290
%% check inflation with merge
@@ -288,11 +295,14 @@ is_inflation_test() ->
288295

289296
is_strict_inflation_test() ->
290297
Counter1 = {?TYPE, [{1, 2}, {2, 1}, {4, 1}]},
298+
DeltaCounter1 = {?TYPE, {delta, [{1, 2}, {2, 1}, {4, 1}]}},
291299
Counter2 = {?TYPE, [{1, 2}, {2, 1}, {4, 1}, {5, 6}]},
292300
Counter3 = {?TYPE, [{1, 2}, {2, 2}, {4, 1}]},
293301
Counter4 = {?TYPE, [{1, 2}, {2, 1}]},
294302
?assertNot(is_strict_inflation(Counter1, Counter1)),
295303
?assert(is_strict_inflation(Counter1, Counter2)),
304+
?assertNot(is_strict_inflation(DeltaCounter1, Counter1)),
305+
?assert(is_strict_inflation(DeltaCounter1, Counter2)),
296306
?assert(is_strict_inflation(Counter1, Counter3)),
297307
?assertNot(is_strict_inflation(Counter1, Counter4)).
298308

src/state_gmap.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ equal({?TYPE, {Type, GMap1}}, {?TYPE, {Type, GMap2}}) ->
143143
%% - for each key in the first `state_gmap()',
144144
%% the correspondent value in the second `state_gmap()'
145145
%% should be an inflation of the value in the first.
146-
-spec is_inflation(state_gmap(), state_gmap()) -> boolean().
146+
-spec is_inflation(delta_or_state(), state_gmap()) -> boolean().
147+
is_inflation({?TYPE, {delta, {Type, _GMap1}=G1}}, {?TYPE, {Type, _GMap2}=G2}) ->
148+
is_inflation({?TYPE, G1}, {?TYPE, G2});
147149
is_inflation({?TYPE, {Type, GMap1}}, {?TYPE, {Type, GMap2}}) ->
148150
lists_ext:iterate_until(
149151
fun({Key, Value1}) ->
@@ -158,7 +160,9 @@ is_inflation({?TYPE, {Type, GMap1}}, {?TYPE, {Type, GMap2}}) ->
158160
).
159161

160162
%% @doc Check for strict inflation.
161-
-spec is_strict_inflation(state_gmap(), state_gmap()) -> boolean().
163+
-spec is_strict_inflation(delta_or_state(), state_gmap()) -> boolean().
164+
is_strict_inflation({?TYPE, {delta, {Type, _GMap1}=G1}}, {?TYPE, {Type, _GMap2}=G2}) ->
165+
is_strict_inflation({?TYPE, G1}, {?TYPE, G2});
162166
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
163167
state_type:is_strict_inflation(CRDT1, CRDT2).
164168

@@ -232,10 +236,13 @@ equal_test() ->
232236

233237
is_inflation_test() ->
234238
Map1 = {?TYPE, {?GCOUNTER_TYPE, [{<<"key1">>, {?GCOUNTER_TYPE, [{1, 1}]}}]}},
239+
DeltaMap1 = {?TYPE, {delta, {?GCOUNTER_TYPE, [{<<"key1">>, {?GCOUNTER_TYPE, [{1, 1}]}}]}}},
235240
Map2 = {?TYPE, {?GCOUNTER_TYPE, [{<<"key1">>, {?GCOUNTER_TYPE, [{1, 2}]}}]}},
236241
Map3 = {?TYPE, {?GCOUNTER_TYPE, [{<<"key2">>, {?GCOUNTER_TYPE, [{1, 1}]}}]}},
237242
?assert(is_inflation(Map1, Map1)),
238243
?assert(is_inflation(Map1, Map2)),
244+
?assert(is_inflation(DeltaMap1, Map1)),
245+
?assert(is_inflation(DeltaMap1, Map2)),
239246
?assertNot(is_inflation(Map1, Map3)),
240247
%% check inflation with merge
241248
?assert(state_type:is_inflation(Map1, Map1)),
@@ -244,10 +251,13 @@ is_inflation_test() ->
244251

245252
is_strict_inflation_test() ->
246253
Map1 = {?TYPE, {?GCOUNTER_TYPE, [{<<"key1">>, {?GCOUNTER_TYPE, [{1, 1}]}}]}},
254+
DeltaMap1 = {?TYPE, {delta, {?GCOUNTER_TYPE, [{<<"key1">>, {?GCOUNTER_TYPE, [{1, 1}]}}]}}},
247255
Map2 = {?TYPE, {?GCOUNTER_TYPE, [{<<"key1">>, {?GCOUNTER_TYPE, [{1, 2}]}}]}},
248256
Map3 = {?TYPE, {?GCOUNTER_TYPE, [{<<"key2">>, {?GCOUNTER_TYPE, [{1, 1}]}}]}},
249257
?assertNot(is_strict_inflation(Map1, Map1)),
250258
?assert(is_strict_inflation(Map1, Map2)),
259+
?assertNot(is_strict_inflation(DeltaMap1, Map1)),
260+
?assert(is_strict_inflation(DeltaMap1, Map2)),
251261
?assertNot(is_strict_inflation(Map1, Map3)).
252262

253263
join_decomposition_test() ->

src/state_gset.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,12 +119,16 @@ equal({?TYPE, GSet1}, {?TYPE, GSet2}) ->
119119
%% of the first.
120120
%% The second `state_gset()' is an inflation if the first set is
121121
%% a subset of the second.
122-
-spec is_inflation(state_gset(), state_gset()) -> boolean().
122+
-spec is_inflation(delta_or_state(), state_gset()) -> boolean().
123+
is_inflation({?TYPE, {delta, GSet1}}, {?TYPE, GSet2}) ->
124+
is_inflation({?TYPE, GSet1}, {?TYPE, GSet2});
123125
is_inflation({?TYPE, GSet1}, {?TYPE, GSet2}) ->
124126
ordsets:is_subset(GSet1, GSet2).
125127

126128
%% @doc Check for strict inflation.
127-
-spec is_strict_inflation(state_gset(), state_gset()) -> boolean().
129+
-spec is_strict_inflation(delta_or_state(), state_gset()) -> boolean().
130+
is_strict_inflation({?TYPE, {delta, GSet1}}, {?TYPE, GSet2}) ->
131+
is_strict_inflation({?TYPE, GSet1}, {?TYPE, GSet2});
128132
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
129133
state_type:is_strict_inflation(CRDT1, CRDT2).
130134

@@ -215,9 +219,12 @@ equal_test() ->
215219

216220
is_inflation_test() ->
217221
Set1 = {?TYPE, [<<"a">>]},
222+
DeltaSet1 = {?TYPE, {delta, [<<"a">>]}},
218223
Set2 = {?TYPE, [<<"a">>, <<"b">>]},
219224
?assert(is_inflation(Set1, Set1)),
220225
?assert(is_inflation(Set1, Set2)),
226+
?assert(is_inflation(DeltaSet1, Set1)),
227+
?assert(is_inflation(DeltaSet1, Set2)),
221228
?assertNot(is_inflation(Set2, Set1)),
222229
%% check inflation with merge
223230
?assert(state_type:is_inflation(Set1, Set1)),
@@ -226,9 +233,12 @@ is_inflation_test() ->
226233

227234
is_strict_inflation_test() ->
228235
Set1 = {?TYPE, [<<"a">>]},
236+
DeltaSet1 = {?TYPE, {delta, [<<"a">>]}},
229237
Set2 = {?TYPE, [<<"a">>, <<"b">>]},
230238
?assertNot(is_strict_inflation(Set1, Set1)),
231239
?assert(is_strict_inflation(Set1, Set2)),
240+
?assertNot(is_strict_inflation(DeltaSet1, Set1)),
241+
?assert(is_strict_inflation(DeltaSet1, Set2)),
232242
?assertNot(is_strict_inflation(Set2, Set1)).
233243

234244
join_decomposition_test() ->

src/state_ivar.erl

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242

4343
-opaque state_ivar() :: {?TYPE, payload()}.
4444
-opaque delta_state_ivar() :: {?TYPE, {delta, payload()}}.
45+
-type delta_or_state() :: state_ivar() | delta_state_ivar().
4546
-type payload() :: term().
4647
-type state_ivar_op() :: {set, term()}.
4748

@@ -74,7 +75,7 @@ query({?TYPE, Value}) ->
7475
Value.
7576

7677
%% @doc Merge two `state_ivar()'.
77-
-spec merge(state_ivar(), state_ivar()) -> state_ivar().
78+
-spec merge(delta_or_state(), delta_or_state()) -> state_ivar().
7879
merge({?TYPE, undefined}, {?TYPE, undefined}) ->
7980
{?TYPE, undefined};
8081
merge({?TYPE, {delta, Value}}, {?TYPE, undefined}) ->
@@ -97,7 +98,9 @@ equal({?TYPE, Value1}, {?TYPE, Value2}) ->
9798
%% of the first.
9899
%% The second `state_ivar()' is and inflation if the first set is
99100
%% a subset of the second.
100-
-spec is_inflation(state_ivar(), state_ivar()) -> boolean().
101+
-spec is_inflation(delta_or_state(), state_ivar()) -> boolean().
102+
is_inflation({?TYPE, {delta, Value1}}, {?TYPE, Value2}) ->
103+
is_inflation({?TYPE, Value1}, {?TYPE, Value2});
101104
is_inflation({?TYPE, undefined}, {?TYPE, undefined}) ->
102105
true;
103106
is_inflation({?TYPE, undefined}, {?TYPE, _Value}) ->
@@ -108,7 +111,9 @@ is_inflation({?TYPE, _}=Var1, {?TYPE, _}=Var2) ->
108111
equal(Var1, Var2).
109112

110113
%% @doc Check for strict inflation.
111-
-spec is_strict_inflation(state_ivar(), state_ivar()) -> boolean().
114+
-spec is_strict_inflation(delta_or_state(), state_ivar()) -> boolean().
115+
is_strict_inflation({?TYPE, {delta, Value1}}, {?TYPE, Value2}) ->
116+
is_strict_inflation({?TYPE, Value1}, {?TYPE, Value2});
112117
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
113118
state_type:is_strict_inflation(CRDT1, CRDT2).
114119

@@ -161,11 +166,14 @@ equal_test() ->
161166
is_inflation_test() ->
162167
Var0 = new(),
163168
Var1 = {?TYPE, [<<"a">>]},
169+
DeltaVar1 = {?TYPE, {delta, [<<"a">>]}},
164170
Var2 = {?TYPE, [<<"b">>]},
165171
?assert(is_inflation(Var0, Var0)),
166172
?assert(is_inflation(Var0, Var1)),
167173
?assert(is_inflation(Var1, Var1)),
168174
?assertNot(is_inflation(Var1, Var2)),
175+
?assert(is_inflation(DeltaVar1, Var1)),
176+
?assertNot(is_inflation(DeltaVar1, Var2)),
169177
?assertNot(is_inflation(Var2, Var1)),
170178
%% check inflation with merge
171179
?assert(state_type:is_inflation(Var0, Var0)),
@@ -175,11 +183,14 @@ is_inflation_test() ->
175183
is_strict_inflation_test() ->
176184
Var0 = new(),
177185
Var1 = {?TYPE, [<<"a">>]},
186+
DeltaVar1 = {?TYPE, {delta, [<<"a">>]}},
178187
Var2 = {?TYPE, [<<"b">>]},
179188
?assertNot(is_strict_inflation(Var0, Var0)),
180189
?assert(is_strict_inflation(Var0, Var1)),
181190
?assertNot(is_strict_inflation(Var1, Var1)),
182191
?assertNot(is_strict_inflation(Var1, Var2)),
192+
?assertNot(is_strict_inflation(DeltaVar1, Var1)),
193+
?assertNot(is_strict_inflation(DeltaVar1, Var2)),
183194
?assertNot(is_strict_inflation(Var2, Var1)).
184195

185196
join_decomposition_test() ->

src/state_lexcounter.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ equal({?TYPE, LexCounter1}, {?TYPE, LexCounter2}) ->
156156
%% component of P1
157157
%% - their first components are equal and the second component
158158
%% of P2 is and inflation of the second component of P1
159-
-spec is_inflation(state_lexcounter(), state_lexcounter()) -> boolean().
159+
-spec is_inflation(delta_or_state(), state_lexcounter()) -> boolean().
160+
is_inflation({?TYPE, {delta, LexCounter1}}, {?TYPE, LexCounter2}) ->
161+
is_inflation({?TYPE, LexCounter1}, {?TYPE, LexCounter2});
160162
is_inflation({?TYPE, LexCounter1}, {?TYPE, LexCounter2}) ->
161163
LexPairInflation = fun({Left1, Right1}, {Left2, Right2}) ->
162164
(Left2 > Left1)
@@ -176,7 +178,9 @@ is_inflation({?TYPE, LexCounter1}, {?TYPE, LexCounter2}) ->
176178
).
177179

178180
%% @doc Check for strict inflation.
179-
-spec is_strict_inflation(state_lexcounter(), state_lexcounter()) -> boolean().
181+
-spec is_strict_inflation(delta_or_state(), state_lexcounter()) -> boolean().
182+
is_strict_inflation({?TYPE, {delta, LexCounter1}}, {?TYPE, LexCounter2}) ->
183+
is_strict_inflation({?TYPE, LexCounter1}, {?TYPE, LexCounter2});
180184
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
181185
state_type:is_strict_inflation(CRDT1, CRDT2).
182186

@@ -259,12 +263,15 @@ equal_test() ->
259263

260264
is_inflation_test() ->
261265
Counter1 = {?TYPE, [{<<"1">>, {2, 0}}]},
266+
DeltaCounter1 = {?TYPE, {delta, [{<<"1">>, {2, 0}}]}},
262267
Counter2 = {?TYPE, [{<<"1">>, {2, 0}}, {<<"2">>, {1, -1}}]},
263268
Counter3 = {?TYPE, [{<<"1">>, {2, 1}}]},
264269
Counter4 = {?TYPE, [{<<"1">>, {3, -2}}]},
265270
Counter5 = {?TYPE, [{<<"1">>, {2, -1}}]},
266271
?assert(is_inflation(Counter1, Counter1)),
267272
?assert(is_inflation(Counter1, Counter2)),
273+
?assert(is_inflation(DeltaCounter1, Counter1)),
274+
?assert(is_inflation(DeltaCounter1, Counter2)),
268275
?assertNot(is_inflation(Counter2, Counter1)),
269276
?assert(is_inflation(Counter1, Counter3)),
270277
?assert(is_inflation(Counter1, Counter4)),
@@ -279,12 +286,15 @@ is_inflation_test() ->
279286

280287
is_strict_inflation_test() ->
281288
Counter1 = {?TYPE, [{<<"1">>, {2, 0}}]},
289+
DeltaCounter1 = {?TYPE, {delta, [{<<"1">>, {2, 0}}]}},
282290
Counter2 = {?TYPE, [{<<"1">>, {2, 0}}, {<<"2">>, {1, -1}}]},
283291
Counter3 = {?TYPE, [{<<"1">>, {2, 1}}]},
284292
Counter4 = {?TYPE, [{<<"1">>, {3, -2}}]},
285293
Counter5 = {?TYPE, [{<<"1">>, {2, -1}}]},
286294
?assertNot(is_strict_inflation(Counter1, Counter1)),
287295
?assert(is_strict_inflation(Counter1, Counter2)),
296+
?assertNot(is_strict_inflation(DeltaCounter1, Counter1)),
297+
?assert(is_strict_inflation(DeltaCounter1, Counter2)),
288298
?assertNot(is_strict_inflation(Counter2, Counter1)),
289299
?assert(is_strict_inflation(Counter1, Counter3)),
290300
?assert(is_strict_inflation(Counter1, Counter4)),

src/state_max_int.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,12 +101,16 @@ equal({?TYPE, Value1}, {?TYPE, Value2}) ->
101101
%% of the first.
102102
%% The second is an inflation if its value is greater or equal
103103
%% to the value of the first.
104-
-spec is_inflation(state_max_int(), state_max_int()) -> boolean().
104+
-spec is_inflation(delta_or_state(), state_max_int()) -> boolean().
105+
is_inflation({?TYPE, {delta, Value1}}, {?TYPE, Value2}) ->
106+
is_inflation({?TYPE, Value1}, {?TYPE, Value2});
105107
is_inflation({?TYPE, Value1}, {?TYPE, Value2}) ->
106108
Value1 =< Value2.
107109

108110
%% @doc Check for strict inflation.
109-
-spec is_strict_inflation(state_max_int(), state_max_int()) -> boolean().
111+
-spec is_strict_inflation(delta_or_state(), state_max_int()) -> boolean().
112+
is_strict_inflation({?TYPE, {delta, Value1}}, {?TYPE, Value2}) ->
113+
is_strict_inflation({?TYPE, Value1}, {?TYPE, Value2});
110114
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
111115
state_type:is_strict_inflation(CRDT1, CRDT2).
112116

@@ -184,9 +188,12 @@ equal_test() ->
184188

185189
is_inflation_test() ->
186190
MaxInt1 = {?TYPE, 23},
191+
DeltaMaxInt1 = {?TYPE, {delta, 23}},
187192
MaxInt2 = {?TYPE, 42},
188193
?assert(is_inflation(MaxInt1, MaxInt1)),
189194
?assert(is_inflation(MaxInt1, MaxInt2)),
195+
?assert(is_inflation(DeltaMaxInt1, MaxInt1)),
196+
?assert(is_inflation(DeltaMaxInt1, MaxInt2)),
190197
?assertNot(is_inflation(MaxInt2, MaxInt1)),
191198
%% check inflation with merge
192199
?assert(state_type:is_inflation(MaxInt1, MaxInt1)),
@@ -195,9 +202,12 @@ is_inflation_test() ->
195202

196203
is_strict_inflation_test() ->
197204
MaxInt1 = {?TYPE, 23},
205+
DeltaMaxInt1 = {?TYPE, {delta, 23}},
198206
MaxInt2 = {?TYPE, 42},
199207
?assertNot(is_strict_inflation(MaxInt1, MaxInt1)),
200208
?assert(is_strict_inflation(MaxInt1, MaxInt2)),
209+
?assertNot(is_strict_inflation(DeltaMaxInt1, MaxInt1)),
210+
?assert(is_strict_inflation(DeltaMaxInt1, MaxInt2)),
201211
?assertNot(is_strict_inflation(MaxInt2, MaxInt1)).
202212

203213
join_decomposition_test() ->

src/state_orset.erl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,9 @@ equal({?TYPE, ORSet1}, {?TYPE, ORSet2}) ->
211211
%% - active on both
212212
%% - inactive on both
213213
%% - first active and second inactive
214-
-spec is_inflation(state_orset(), state_orset()) -> boolean().
214+
-spec is_inflation(delta_or_state(), state_orset()) -> boolean().
215+
is_inflation({?TYPE, {delta, ORSet1}}, {?TYPE, ORSet2}) ->
216+
is_inflation({?TYPE, ORSet1}, {?TYPE, ORSet2});
215217
is_inflation({?TYPE, ORSet1}, {?TYPE, ORSet2}) ->
216218
lists_ext:iterate_until(
217219
fun({Elem, Tokens1}) ->
@@ -245,7 +247,9 @@ is_inflation({?TYPE, ORSet1}, {?TYPE, ORSet2}) ->
245247
).
246248

247249
%% @doc Check for strict inflation.
248-
-spec is_strict_inflation(state_orset(), state_orset()) -> boolean().
250+
-spec is_strict_inflation(delta_or_state(), state_orset()) -> boolean().
251+
is_strict_inflation({?TYPE, {delta, ORSet1}}, {?TYPE, ORSet2}) ->
252+
is_strict_inflation({?TYPE, ORSet1}, {?TYPE, ORSet2});
249253
is_strict_inflation({?TYPE, _}=CRDT1, {?TYPE, _}=CRDT2) ->
250254
state_type:is_strict_inflation(CRDT1, CRDT2).
251255

@@ -391,10 +395,13 @@ equal_test() ->
391395

392396
is_inflation_test() ->
393397
Set1 = {?TYPE, [{<<"a">>, [{<<"token1">>, true}]}]},
398+
DeltaSet1 = {?TYPE, {delta, [{<<"a">>, [{<<"token1">>, true}]}]}},
394399
Set2 = {?TYPE, [{<<"a">>, [{<<"token1">>, false}]}]},
395400
Set3 = {?TYPE, [{<<"a">>, [{<<"token1">>, true}]}, {<<"b">>, [{<<"token2">>, false}]}]},
396401
?assert(is_inflation(Set1, Set1)),
397402
?assert(is_inflation(Set1, Set2)),
403+
?assert(is_inflation(DeltaSet1, Set1)),
404+
?assert(is_inflation(DeltaSet1, Set2)),
398405
?assertNot(is_inflation(Set2, Set1)),
399406
?assert(is_inflation(Set1, Set3)),
400407
?assertNot(is_inflation(Set2, Set3)),
@@ -409,10 +416,13 @@ is_inflation_test() ->
409416

410417
is_strict_inflation_test() ->
411418
Set1 = {?TYPE, [{<<"a">>, [{<<"token1">>, true}]}]},
419+
DeltaSet1 = {?TYPE, {delta, [{<<"a">>, [{<<"token1">>, true}]}]}},
412420
Set2 = {?TYPE, [{<<"a">>, [{<<"token1">>, false}]}]},
413421
Set3 = {?TYPE, [{<<"a">>, [{<<"token1">>, true}]}, {<<"b">>, [{<<"token2">>, false}]}]},
414422
?assertNot(is_strict_inflation(Set1, Set1)),
415423
?assert(is_strict_inflation(Set1, Set2)),
424+
?assertNot(is_strict_inflation(DeltaSet1, Set1)),
425+
?assert(is_strict_inflation(DeltaSet1, Set2)),
416426
?assertNot(is_strict_inflation(Set2, Set1)),
417427
?assert(is_strict_inflation(Set1, Set3)),
418428
?assertNot(is_strict_inflation(Set2, Set3)),

0 commit comments

Comments
 (0)