|
22 | 22 | -export([new/0, |
23 | 23 | get_root/1, |
24 | 24 | get_keep_while_conds/1, |
| 25 | + assert_equal/2, |
25 | 26 |
|
26 | 27 | are_keep_while_conditions_met/2, |
27 | 28 |
|
|
39 | 40 |
|
40 | 41 | -record(tree, {root = #node{} :: khepri_tree:tree_node(), |
41 | 42 | keep_while_conds = #{} :: khepri_tree:keep_while_conds_map(), |
42 | | - keep_while_conds_revidx = #{} :: |
43 | | - khepri_tree:keep_while_conds_revidx()}). |
| 43 | + keep_while_conds_revidx = #{}}). |
44 | 44 |
|
45 | 45 | -type tree_node() :: #node{}. |
46 | 46 | %% A node in the tree structure. |
47 | 47 |
|
48 | | --opaque tree_v0() :: #tree{keep_while_conds_revidx :: |
49 | | - khepri_tree:keep_while_conds_revidx_v0()}. |
50 | | --opaque tree_v1() :: #tree{keep_while_conds_revidx :: |
51 | | - khepri_tree:keep_while_conds_revidx_v1()}. |
| 48 | +-type tree(KeepWhileCondsRevIdxType) :: #tree{keep_while_conds_revidx :: |
| 49 | + KeepWhileCondsRevIdxType}. |
| 50 | + |
| 51 | +-opaque tree_v0() :: tree(khepri_tree:keep_while_conds_revidx_v0()). |
| 52 | +-opaque tree_v1() :: tree(khepri_tree:keep_while_conds_revidx_v1()). |
52 | 53 |
|
53 | 54 | -type tree() :: tree_v0() | tree_v1(). |
54 | 55 |
|
@@ -125,6 +126,14 @@ get_root(#tree{root = Root}) -> |
125 | 126 | get_keep_while_conds(#tree{keep_while_conds = KeepWhileConds}) -> |
126 | 127 | KeepWhileConds. |
127 | 128 |
|
| 129 | +-spec assert_equal(Tree1, Tree2) -> ok when |
| 130 | + Tree1 :: khepri_tree:tree(), |
| 131 | + Tree2 :: khepri_tree:tree(). |
| 132 | + |
| 133 | +assert_equal(#tree{} = Tree1, #tree{} = Tree2) -> |
| 134 | + ?assertEqual(Tree1, Tree2), |
| 135 | + ok. |
| 136 | + |
128 | 137 | -spec create_node_record(Payload) -> Node when |
129 | 138 | Payload :: khepri_payload:payload(), |
130 | 139 | Node :: tree_node(). |
@@ -312,9 +321,10 @@ squash_version_bumps_after_keep_while( |
312 | 321 | %% Keep-while functions. |
313 | 322 | %% ------------------------------------------------------------------- |
314 | 323 |
|
315 | | --spec to_absolute_keep_while(BasePath, KeepWhile) -> KeepWhile when |
| 324 | +-spec to_absolute_keep_while(BasePath, KeepWhile) -> AbsKeepWhile when |
316 | 325 | BasePath :: khepri_path:native_path(), |
317 | | - KeepWhile :: khepri_condition:native_keep_while(). |
| 326 | + KeepWhile :: khepri_condition:native_keep_while(), |
| 327 | + AbsKeepWhile :: khepri_condition:native_keep_while(). |
318 | 328 | %% @private |
319 | 329 |
|
320 | 330 | to_absolute_keep_while(BasePath, KeepWhile) -> |
@@ -379,18 +389,24 @@ is_keep_while_condition_met_on_self( |
379 | 389 | true |
380 | 390 | end. |
381 | 391 |
|
| 392 | +-spec update_keep_while_conds(Tree, Watcher, KeepWhile) -> NewTree when |
| 393 | + Tree :: khepri_tree:tree(), |
| 394 | + Watcher :: khepri_path:native_path(), |
| 395 | + KeepWhile :: khepri_condition:native_keep_while(), |
| 396 | + NewTree :: khepri_tree:tree(). |
| 397 | + |
382 | 398 | update_keep_while_conds(Tree, Watcher, KeepWhile) -> |
383 | 399 | AbsKeepWhile = to_absolute_keep_while(Watcher, KeepWhile), |
384 | 400 | Tree1 = update_keep_while_conds_revidx(Tree, Watcher, AbsKeepWhile), |
385 | | - #tree{keep_while_conds = KeepWhileConds} = Tree1, |
| 401 | + KeepWhileConds = get_keep_while_conds(Tree1), |
386 | 402 | KeepWhileConds1 = KeepWhileConds#{Watcher => AbsKeepWhile}, |
387 | 403 | Tree1#tree{keep_while_conds = KeepWhileConds1}. |
388 | 404 |
|
389 | | --spec update_keep_while_conds_revidx(Tree, Watcher, KeepWhile) -> |
390 | | - Tree when |
| 405 | +-spec update_keep_while_conds_revidx(Tree, Watcher, KeepWhile) -> NewTree when |
391 | 406 | Tree :: tree(), |
392 | 407 | Watcher :: khepri_path:native_path(), |
393 | | - KeepWhile :: khepri_condition:native_keep_while(). |
| 408 | + KeepWhile :: khepri_condition:native_keep_while(), |
| 409 | + NewTree :: tree(). |
394 | 410 |
|
395 | 411 | update_keep_while_conds_revidx( |
396 | 412 | #tree{keep_while_conds_revidx = KeepWhileCondsRevIdx} = Tree, |
|
0 commit comments