Add has_store_maps function

This commit is contained in:
Ulf Norell 2019-08-12 14:40:34 +02:00
parent 5aee70b8ff
commit 15095a74ab

View File

@ -11,6 +11,7 @@
-include("aeb_fate_data.hrl"). -include("aeb_fate_data.hrl").
-export([ allocate_store_maps/2 -export([ allocate_store_maps/2
, has_store_maps/1
, unfold_store_maps/2 , unfold_store_maps/2
, refcount/1 , refcount/1
, refcount_zero/0 , refcount_zero/0
@ -151,10 +152,15 @@ refcount_union(A, B) ->
maps:fold(fun(K, N, C) -> maps:update_with(K, fun(M) -> M + N end, N, C) end, maps:fold(fun(K, N, C) -> maps:update_with(K, fun(M) -> M + N end, N, C) end,
B, A). B, A).
-spec has_store_maps(fate_value()) -> boolean().
has_store_maps(Val) ->
refcount_zero() /= refcount(Val).
-spec refcount(fate_value()) -> refcount(). -spec refcount(fate_value()) -> refcount().
refcount(Val) -> refcount(Val, #{}). refcount(Val) -> refcount(Val, #{}).
-spec refcount(refcount(), fate_value()) -> refcount(). -spec refcount(refcount(), fate_value()) -> refcount().
refcount(?FATE_MAP_TOMBSTONE, Count) -> Count;
refcount(?FATE_TRUE, Count) -> Count; refcount(?FATE_TRUE, Count) -> Count;
refcount(?FATE_FALSE, Count) -> Count; refcount(?FATE_FALSE, Count) -> Count;
refcount(?FATE_UNIT, Count) -> Count; refcount(?FATE_UNIT, Count) -> Count;
@ -184,7 +190,8 @@ refcount_l(Vals, Count) ->
refcount_m(Val, Count) -> refcount_m(Val, Count) ->
%% No maps in map keys %% No maps in map keys
maps:fold(fun(_, V, C) -> refcount(V, C) end, Count, Val). maps:fold(fun(_, ?FATE_MAP_TOMBSTONE, C) -> C;
(_, V, C) -> refcount(V, C) end, Count, Val).
%% -- Map id allocation ------------------------------------------------------ %% -- Map id allocation ------------------------------------------------------