anchor.diff:            % {seq_id(), rep_id()} -> fail_info()
             input_map  = gb_trees:empty() :: disco_gbtree({seq_id(), rep_id()}, fail_info()),
             is_input_done                 :: boolean(),
  +          stage_grouping                :: label_grouping(),
  +          stage_group                   :: group(),
             max_seq_id                    :: seq_id()}).
   -type state() :: #state{}.
   
  
positive.code:                             || {SeqId, {_Id, DI}} <- SeqInputs]),
      #state{inputs     = gb_trees:from_orddict(SeqInputs),
             input_map  = gb_trees:from_orddict(SeqMap),
             %TODO only set input as done when we know it is done.
             is_input_done = true,
             max_seq_id = length(Inputs)}.
  
  -spec init_replicas(seq_id(), data_input(), label_grouping(), group())
  
negative.code: 
  -spec add_inputs(done | [{input_id(), data_input()}], state()) -> state().
  add_inputs(done, S) ->
      S#state{is_input_done = true};
  add_inputs([], S) ->
      S;
  
  %TODO This function can be made much faster.
  add_inputs([NewInput|Rest], #state{inputs = Inputs,
                                     max_seq_id = MaxSeqId,
                                     stage_grouping = Grouping,
                                     stage_group = Group,
                                     input_map = Map} = S) ->
      Contains = lists:foldl(fun({_, Inp}, T) ->
                                 case T of
                                     true -> true;
                                     false ->
                                         case Inp of
                                             NewInput -> true;
                                             _        -> false
                                         end
                                 end
                             end, false, gb_trees:to_list(Inputs)),
     case Contains of
         true ->
             add_inputs(Rest, S);
         false ->
          {_Id, DI} = NewInput,
          Map1 = lists:foldl(fun({K, V}, IMap) -> gb_trees:enter(K, V, IMap) end,
                             Map, init_replicas(MaxSeqId, DI, Grouping, Group)),
          add_inputs(Rest,
              S#state{inputs = gb_trees:enter(MaxSeqId, NewInput, Inputs),
                      max_seq_id = MaxSeqId + 1,
                      input_map = Map1})
      end.
  
  -spec all_seq_ids(state()) -> [seq_id()].
  all_seq_ids(#state{max_seq_id = MaxSeqId}) ->
  