Skip to content
This repository has been archived by the owner on May 27, 2022. It is now read-only.

Commit

Permalink
keep type names short
Browse files Browse the repository at this point in the history
  • Loading branch information
gyounes committed Feb 5, 2018
1 parent a2fe3d5 commit 303dc70
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
16 changes: 8 additions & 8 deletions src/antidote_crdt_flag_dw.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@
-define(TAG, 77).
-define(V1_VERS, 1).

-export_type([antidote_crdt_flag_dw/0]).
-opaque antidote_crdt_flag_dw() :: {antidote_crdt_flag_helper:tokens(), antidote_crdt_flag_helper:tokens()}.
-export_type([flag_dw/0]).
-opaque flag_dw() :: {antidote_crdt_flag_helper:tokens(), antidote_crdt_flag_helper:tokens()}.

%% SeenTokens, NewEnableTokens, NewDisableTokens
-type downstream_op() :: {antidote_crdt_flag_helper:tokens(), antidote_crdt_flag_helper:tokens(), antidote_crdt_flag_helper:tokens()}.

-spec new() -> antidote_crdt_flag_dw().
-spec new() -> flag_dw().
new() ->
{[], []}.

-spec value(antidote_crdt_flag_dw()) -> boolean().
-spec value(flag_dw()) -> boolean().
value({EnableTokens, DisableTokens}) ->
DisableTokens == [] andalso EnableTokens =/= [].

-spec downstream(antidote_crdt_flag_helper:op(), antidote_crdt_flag_dw()) -> {ok, downstream_op()}.
-spec downstream(antidote_crdt_flag_helper:op(), flag_dw()) -> {ok, downstream_op()}.
downstream({disable, {}}, {EnableTokens, DisableTokens}) ->
{ok, {EnableTokens ++ DisableTokens, [], [antidote_crdt_flag_helper:unique()]}};
downstream({enable, {}}, {EnableTokens, DisableTokens}) ->
{ok, {EnableTokens ++ DisableTokens, [antidote_crdt_flag_helper:unique()], []}};
downstream({reset, {}}, {EnableTokens, DisableTokens}) ->
{ok, {EnableTokens ++ DisableTokens, [], []}}.

-spec update(downstream_op(), antidote_crdt_flag_dw()) -> {ok, antidote_crdt_flag_dw()}.
-spec update(downstream_op(), flag_dw()) -> {ok, flag_dw()}.
update({SeenTokens, NewEnableTokens, NewDisableTokens}, {CurrentEnableTokens, CurrentDisableTokens}) ->
FinalEnableTokens = (CurrentEnableTokens ++ NewEnableTokens) -- SeenTokens,
FinalDisableTokens = (CurrentDisableTokens ++ NewDisableTokens) -- SeenTokens,
{ok, {FinalEnableTokens, FinalDisableTokens}}.

-spec equal(antidote_crdt_flag_dw(), antidote_crdt_flag_dw()) -> boolean().
-spec equal(flag_dw(), flag_dw()) -> boolean().
equal(Flag1, Flag2) ->
Flag1 == Flag2.

-spec to_binary(antidote_crdt_flag_dw()) -> antidote_crdt_flag_helper:binary_flag().
-spec to_binary(flag_dw()) -> antidote_crdt_flag_helper:binary_flag().
to_binary(Flag) ->
%% @TODO something smarter
<<?TAG:8/integer, ?V1_VERS:8/integer, (term_to_binary(Flag))/binary>>.
Expand Down
16 changes: 8 additions & 8 deletions src/antidote_crdt_flag_ew.erl
Original file line number Diff line number Diff line change
Expand Up @@ -46,38 +46,38 @@
-define(TAG, 77).
-define(V1_VERS, 1).

-export_type([antidote_crdt_flag_ew/0]).
-opaque antidote_crdt_flag_ew() :: antidote_crdt_flag_helper:flag().
-export_type([flag_ew/0]).
-opaque flag_ew() :: antidote_crdt_flag_helper:flag().

%% SeenTokens, NewTokens
-type downstream_op() :: {antidote_crdt_flag_helper:tokens(), antidote_crdt_flag_helper:tokens()}.

-spec new() -> antidote_crdt_flag_ew().
-spec new() -> flag_ew().
new() ->
[].

-spec value(antidote_crdt_flag_ew()) -> boolean().
-spec value(flag_ew()) -> boolean().
value(EnableTokens) ->
EnableTokens =/= [].

-spec downstream(antidote_crdt_flag_helper:op(), antidote_crdt_flag_ew()) -> {ok, downstream_op()}.
-spec downstream(antidote_crdt_flag_helper:op(), flag_ew()) -> {ok, downstream_op()}.
downstream({disable, {}}, Tokens) ->
{ok, {Tokens, []}};
downstream({enable, {}}, Tokens) ->
{ok, {Tokens, [antidote_crdt_flag_helper:unique()]}};
downstream({reset, {}}, Tokens) ->
{ok, {Tokens, []}}.

-spec update(downstream_op(), antidote_crdt_flag_ew()) -> {ok, antidote_crdt_flag_ew()}.
-spec update(downstream_op(), flag_ew()) -> {ok, flag_ew()}.
update({SeenTokens, NewTokens}, CurrentTokens) ->
FinalTokens = (CurrentTokens ++ NewTokens) -- SeenTokens,
{ok, FinalTokens}.

-spec equal(antidote_crdt_flag_ew(), antidote_crdt_flag_ew()) -> boolean().
-spec equal(flag_ew(), flag_ew()) -> boolean().
equal(Flag1, Flag2) ->
Flag1 == Flag2. % Everything inside is ordered, so this should work

-spec to_binary(antidote_crdt_flag_ew()) -> antidote_crdt_flag_helper:binary_flag().
-spec to_binary(flag_ew()) -> antidote_crdt_flag_helper:binary_flag().
to_binary(Flag) ->
%% @TODO something smarter
<<?TAG:8/integer, ?V1_VERS:8/integer, (term_to_binary(Flag))/binary>>.
Expand Down

0 comments on commit 303dc70

Please sign in to comment.