<commit_before>-module(erlhlc_sync).
-behaviour(gen_server).

-include_lib("hlc/include/hlc.hrl").

-define(SERVER, ?MODULE).

%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------

-export([start_link/1]).

%% ------------------------------------------------------------------
%% gen_server Function Exports
%% ------------------------------------------------------------------

-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------

start_link(ClockFun) ->
    gen_server:start_link({local, ?SERVER}, ?MODULE, [ClockFun], []).

%% ------------------------------------------------------------------
%% gen_server Function Definitions
%% ------------------------------------------------------------------

init([undefined]) ->
    case hlc:new() of
        {ok, C} -> {ok, C};
        Error -> Error
    end;
init([ClockFun]) ->
    case hlc:new(ClockFun) of
        {ok, C} -> {ok, C};
        Error -> Error
    end.

handle_call(now, _From, C) ->
    T = hlc:now(C),
    ?SERVER ! {flood, T},
    {reply, T, C};
handle_call(timestamp, _From, C) ->
    {reply, hlc:timestamp(C), C}.

handle_cast(_Msg, State) ->
    {noreply, State}.

handle_info({update, RT}, C) ->
    CLT = hlc:timestamp(C),
    RTN = RT#timestamp.wall_time + RT#timestamp.logical,
    LTN = CLT#timestamp.wall_time + CLT#timestamp.logical,
    io:format("UPD ~p~n", [RTN - LTN]),
    _LT = hlc:update(C, RT),
    {noreply, C};
handle_info({flood, T}, C) ->
    [{?SERVER, Node} ! {update, T} || Node <- nodes()],
    {noreply, C}.

terminate(_Reason, _State) ->
    ok.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------<commit_msg>update print on beyond thresh-hold<commit_after>-module(erlhlc_sync).
-behaviour(gen_server).

-include_lib("hlc/include/hlc.hrl").

-define(SERVER, ?MODULE).

%% ------------------------------------------------------------------
%% API Function Exports
%% ------------------------------------------------------------------

-export([start_link/1]).

%% ------------------------------------------------------------------
%% gen_server Function Exports
%% ------------------------------------------------------------------

-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
         terminate/2, code_change/3]).

%% ------------------------------------------------------------------
%% API Function Definitions
%% ------------------------------------------------------------------

start_link(ClockFun) ->
    gen_server:start_link({local, ?SERVER}, ?MODULE, [ClockFun], []).

%% ------------------------------------------------------------------
%% gen_server Function Definitions
%% ------------------------------------------------------------------

init([undefined]) ->
    case hlc:new() of
        {ok, C} -> {ok, C};
        Error -> Error
    end;
init([ClockFun]) ->
    case hlc:new(ClockFun) of
        {ok, C} -> {ok, C};
        Error -> Error
    end.

handle_call(now, _From, C) ->
    T = hlc:now(C),
    ?SERVER ! {flood, T},
    {reply, T, C};
handle_call(timestamp, _From, C) ->
    {reply, hlc:timestamp(C), C}.

handle_cast(_Msg, State) ->
    {noreply, State}.

handle_info({update, RT}, C) ->
    CLT = hlc:timestamp(C),
    case (RT#timestamp.wall_time + RT#timestamp.logical)
         - (CLT#timestamp.wall_time + CLT#timestamp.logical) of
        TNDiff when TNDiff > 1000 ->
            io:format("UPD ~p~n", [TNDiff]);
        TNDiff when TNDiff < -1000 ->
            io:format("UPD ~p~n", [TNDiff]);
        _ -> ok
    end,
    _LT = hlc:update(C, RT),
    {noreply, C};
handle_info({flood, T}, C) ->
    [{?SERVER, Node} ! {update, T} || Node <- nodes()],
    {noreply, C}.

terminate(_Reason, _State) ->
    ok.

code_change(_OldVsn, State, _Extra) ->
    {ok, State}.

%% ------------------------------------------------------------------
%% Internal Function Definitions
%% ------------------------------------------------------------------
{'fraction_non_alphanumeric': 0.43292405638926784, 'fraction_numerical': 0.0050022737608003635, 'mean_word_length': 1.093764873869586, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '6051105', 'n_tokens_mistral': 1214, 'n_tokens_neox': 1180, 'n_words': 244}