anchor.diff:  %%%=============================================================================
   %%% Internal functions
   %%%=============================================================================
  -subscribe_topic({Topic, Qos}, SubPid) ->
  -	case mnesia:transaction(fun trie_add/1, [Topic]) of
  -	{atomic, _} ->	
  -		case get({subscriber, SubPid}) of
  -		undefined -> 
  -            %%TODO: refactor later...
  -			MonRef = erlang:monitor(process, SubPid),
  -			put({subcriber, SubPid}, MonRef),
  -			put({submon, MonRef}, SubPid);
  -		_ ->
  -			already_monitored
  -		end,
  -        %% remove duplicated subscribers
  -        try_remove_subscriber({Topic, Qos}, SubPid),
  -		ets:insert(topic_subscriber, #topic_subscriber{topic=Topic, qos = Qos, subpid=SubPid}),
  -        %TODO: GrantedQos??
  -        {ok, Qos};
  -	{aborted, Reason} ->
  -		{error, Reason}
  -	end.
  -
  -try_remove_subscriber({Topic, Qos}, SubPid) ->
  -    case ets:lookup(topic_subscriber, Topic) of
  -        [] -> 
  -            not_found;
  -        Subs ->
  -            DupSubs = [Sub || Sub = #topic_subscriber{qos = OldQos, subpid = OldPid} 
  -                                    <- Subs, Qos =/= OldQos, OldPid =:= SubPid],
  -            case DupSubs of
  -                [] -> ok;
  -                [DupSub] -> 
  -                    lager:warning("PubSub: remove duplicated subscriber ~p", [DupSub]), 
  -                    ets:delete(topic_subscriber, DupSub)
  -            end
  -    end.
   
   try_remove_topic(Name) when is_binary(Name) ->
   	case ets:member(topic_subscriber, Name) of
  
positive.code: %% ------------------------------------------------------------------
  
  init([]) ->
  	mnesia:create_table(topic_trie, [
  		{ram_copies, [node()]},
  		{attributes, record_info(fields, topic_trie)}]),
  	mnesia:create_table(topic_trie_node, [
  		{ram_copies, [node()]},
  		{attributes, record_info(fields, topic_trie_node)}]),
  	mnesia:create_table(topic, [
  		{type, bag},
  		{record_name, topic},
  		{ram_copies, [node()]}, 
  		{attributes, record_info(fields, topic)}]),
  	mnesia:add_table_copy(topic_trie, node(), ram_copies),
  	mnesia:add_table_copy(topic_trie_node, node(), ram_copies),
  	mnesia:add_table_copy(topic, node(), ram_copies),
  	ets:new(topic_subscriber, [bag, named_table, {keypos, 2}]),
  	{ok, #state{}}.
  
  handle_call(getstats, _From, State = #state{max_subs = Max}) ->
      Stats = [{'topics/count', mnesia:table_info(topic, size)},
               {'subscribers/count', ets:info(topic_subscriber, size)},
               {'subscribers/max', Max}],
      {reply, Stats, State};
  
  handle_call({create, Topic}, _From, State) ->
  	Result = mnesia:transaction(fun trie_add/1, [Topic]),
      {reply, Result, setstats(State)};
  
  handle_call({subscribe, Topics, SubPid}, _From, State) ->
      Result = [subscribe_topic({Topic, Qos}, SubPid) || {Topic, Qos} <- Topics],
      Reply = 
      case [Err || Err = {error, _} <- Result] of
          [] -> {ok, [Qos || {ok, Qos} <- Result]};
          Errors -> hd(Errors)
      end,
      {reply, Reply, setstats(State)};
  
  handle_call(Req, _From, State) ->
  	{stop, {badreq, Req}, State}.
  
negative.code: 
  -export([topics/0,
          create/1,
  		subscribe/1,
  		unsubscribe/1,
  		publish/1,
  		publish/2,
          %local node
  