<commit_before>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2014 SyncFree Consortium.  All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License.  You may obtain
%% a copy of the License at
%%
%%   http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------

-module(lasp_riak_keylist_program).
-author("<NAME> <<EMAIL>>").

-behavior(lasp_program).

-export([init/1,
         process/4,
         execute/1,
         merge/1,
         sum/1]).

-record(state, {store, type, id, previous}).

-define(CORE, lasp_core).
-define(TYPE, riak_dt_gset).

%% @doc Initialize an or-set as an accumulator.
init(Store) ->
    {ok, Id} = ?CORE:declare(?TYPE, Store),
    {ok, #state{store=Store, id=Id}}.

%% @doc Notification from the system of an event.
process(Object, _Reason, Idx, #state{store=Store, id=Id}=State) ->
    {ok, _} = ?CORE:update(Id, {add, Object}, Idx, Store),
    {ok, State}.

%% @doc Return the result.
execute(#state{store=Store, id=Id, previous=Previous}) ->
    {ok, {_, _, Value}} = ?CORE:read(Id, Previous, Store),
    {ok, Value}.

%% @doc Given a series of outputs, take each one and merge it.
merge(Outputs) ->
    Value = ?TYPE:new(),
    Merged = lists:foldl(fun(X, Acc) -> ?TYPE:merge(X, Acc) end, Value, Outputs),
    {ok, Merged}.

%% @doc Computing a sum accorss nodes is the same as as performing the
%%      merge of outputs between a replica, when dealing with the
%%      set.
sum(Outputs) ->
    Value = ?TYPE:new(),
    Sum = lists:foldl(fun(X, Acc) -> X ++ Acc end, Value, Outputs),
    {ok, Sum}.
<commit_msg>Alter sum to merge operation.<commit_after>%% -------------------------------------------------------------------
%%
%% Copyright (c) 2014 SyncFree Consortium.  All Rights Reserved.
%%
%% This file is provided to you under the Apache License,
%% Version 2.0 (the "License"); you may not use this file
%% except in compliance with the License.  You may obtain
%% a copy of the License at
%%
%%   http://www.apache.org/licenses/LICENSE-2.0
%%
%% Unless required by applicable law or agreed to in writing,
%% software distributed under the License is distributed on an
%% "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
%% KIND, either express or implied.  See the License for the
%% specific language governing permissions and limitations
%% under the License.
%%
%% -------------------------------------------------------------------

-module(lasp_riak_keylist_program).
-author("<NAME> <<EMAIL>>").

-behavior(lasp_program).

-export([init/1,
         process/4,
         execute/1,
         merge/1,
         sum/1]).

-record(state, {store, type, id, previous}).

-define(CORE, lasp_core).
-define(TYPE, riak_dt_gset).

%% @doc Initialize an or-set as an accumulator.
init(Store) ->
    {ok, Id} = ?CORE:declare(?TYPE, Store),
    {ok, #state{store=Store, id=Id}}.

%% @doc Notification from the system of an event.
process(Object, _Reason, Idx, #state{store=Store, id=Id}=State) ->
    {ok, _} = ?CORE:update(Id, {add, Object}, Idx, Store),
    {ok, State}.

%% @doc Return the result.
execute(#state{store=Store, id=Id, previous=Previous}) ->
    {ok, {_, _, Value}} = ?CORE:read(Id, Previous, Store),
    {ok, Value}.

%% @doc Given a series of outputs, take each one and merge it.
merge(Outputs) ->
    Value = ?TYPE:new(),
    Merged = lists:foldl(fun(X, Acc) -> ?TYPE:merge(X, Acc) end, Value, Outputs),
    {ok, Merged}.

%% @doc Computing a sum accorss nodes is the same as as performing the
%%      merge of outputs between a replica, when dealing with the
%%      set.  For a set, it's safe to just perform the merge.
sum(Outputs) ->
    Value = ?TYPE:new(),
    Sum = lists:foldl(fun(X, Acc) -> ?TYPE:merge(X, Acc) end, Value, Outputs),
    {ok, Sum}.

{'fraction_non_alphanumeric': 0.20454545454545456, 'fraction_numerical': 0.006091846298031865, 'mean_word_length': 2.748024582967515, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3810605', 'n_tokens_mistral': 1321, 'n_tokens_neox': 1293, 'n_words': 458}