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

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

-export([start/1]).

-export([send_msg/2, add_user/2, remove_user/2, rename_user/3]).

-include("hub.hrl").

-record(state, {name,
		children = [],
		config = [],
		users = []}).

start({hub, Name, _, _} = Config) ->
    gen_server:start_link({local, Name}, ?MODULE, Config, []).

send_msg(Pid, Msg) ->
    gen_server:cast(Pid, {msg, self(), Msg}).

% returns {ok, UserId}
add_user(Pid, Name) ->
	gen_server:call(Pid, {add_user, Name}).

remove_user(Pid, Id) ->
	gen_server:call(Pid, {remove_user, Id}).

rename_user(Pid, Id, NewName) ->
	gen_server:call(Pid, {rename_user, Id, NewName}).

init({hub, Name, Config, ChildConfig}) ->
	process_flag(trap_exit, true),
    Children = lists:map(fun(X) ->
				spawn_child(X, Name)
			end,
		    ChildConfig),
    {ok, #state{name = Name, children = Children, config = Config}}.

spawn_child({Type, Args} = Config, ParentName) ->
	{ok, Pid} = Type:start(Args, ParentName),
	{Pid, Config}.

call_for_all_except_sender(SenderPid, Func, Args, State) ->
	lists:foreach(fun ({SenderPid, _}) ->
				ok;
			({Pid, {Type, _}}) ->
				apply(Type, Func, [Pid] ++ Args)
			end, State#state.children),
	ok.

gen_user_id(Name, Pid, State) ->
	Id = {random:uniform(fffffffh), Pid},
	case lists:member(Id, State#state.users) of
	true ->
		gen_user_id(Name, Pid, State);
	false ->
		Id
	end.

pid_from_id({_, Pid}, _State) ->
	Pid.<commit_msg>Small fixes<commit_after>-module(hub).
-behaviour(gen_server).

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

-export([start/1]).

-export([send_msg/2, add_user/2, remove_user/2, rename_user/3]).

-include("hub.hrl").

-record(state, {name,
		children = [],
		config = [],
		users = []}).

start({hub, Name, _, _} = Config) ->
    gen_server:start_link({local, Name}, ?MODULE, Config, []).

send_msg(Pid, Msg) ->
    gen_server:cast(Pid, {msg, self(), Msg}).

% returns {ok, UserId}
add_user(Pid, Name) ->
	gen_server:call(Pid, {add_user, Name}).

remove_user(Pid, Id) ->
	gen_server:call(Pid, {remove_user, Id}).

rename_user(Pid, Id, NewName) ->
	gen_server:call(Pid, {rename_user, Id, NewName}).

init({hub, Name, Config, ChildConfig}) ->
	process_flag(trap_exit, true),
    Children = lists:map(fun(X) ->
				spawn_child(X, Name)
			end,
		    ChildConfig),
    {ok, #state{name = Name, children = Children, config = Config}}.

spawn_child({Type, Args} = Config, ParentName) ->
	{ok, Pid} = Type:start(Args, ParentName),
	{Pid, Config}.

call_for_all_except_sender(SenderPid, Func, Args, State) ->
	lists:foreach(fun ({Pid, _}) when Pid == SenderPid ->
				ok;
			({Pid, {Type, _}}) ->
				apply(Type, Func, [Pid] ++ Args)
			end, State#state.children),
	ok.

gen_user_id(Name, Pid, State) ->
	Id = {random:uniform(16#fffffff), Pid},
	case lists:member(Id, State#state.users) of
	true ->
		gen_user_id(Name, Pid, State);
	false ->
		Id
	end.

pid_from_id({_, Pid}, _State) ->
	Pid.
{'fraction_non_alphanumeric': 0.19374597034171503, 'fraction_numerical': 0.007736943907156673, 'mean_word_length': 4.206375838926174, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 2, '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': '6455743', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1262, 'n_words': 243}