anchor.diff:                  ref            :: term(),
                   path           :: string(),
                   itr            :: term(),
  +                write_buffer   :: [{binary(), binary()}],
  +                write_buffer_count :: integer(),
                   dirty_segments :: array()
                  }).
   
  
positive.code: 
  -spec update_snapshot(hashtree()) -> {hashtree(), hashtree()}.
  update_snapshot(State=#state{segments=NumSegments}) ->
      SnapState = snapshot(State),
      State2 = SnapState#state{dirty_segments=bitarray_new(NumSegments)},
      {SnapState, State2}.
  
  -spec update_tree(hashtree()) -> hashtree().
  update_tree(State) ->
      State2 = snapshot(State),
      update_perform(State2).
  
  -spec update_perform(hashtree()) -> hashtree().
  update_perform(State2=#state{dirty_segments=Dirty, segments=NumSegments}) ->
  
negative.code:     HKey = encode(State#state.id, Segment, Key),
      case should_insert(HKey, Opts, State) of
          true ->
              WBuffer = [{HKey, ObjHash} | State#state.write_buffer],
              WCount = State#state.write_buffer_count + 1,
              State2 = State#state{write_buffer=WBuffer,
                                   write_buffer_count=WCount},
              State3 = maybe_flush_buffer(State2),
              %% Dirty = gb_sets:add_element(Segment, State3#state.dirty_segments),
              Dirty = bitarray_set(Segment, State3#state.dirty_segments),
              State3#state{dirty_segments=Dirty};
          false ->
              State
      end.
  
  maybe_flush_buffer(State=#state{write_buffer_count=WCount}) ->
      Threshold = 200,
      case WCount > Threshold of
          true ->
              flush_buffer(State);
          false ->
              State
      end.
  
  flush_buffer(State=#state{write_buffer=WBuffer}) ->
      Updates = [{put, Key, Hash} || {Key, Hash} <- WBuffer],
      ok = eleveldb:write(State#state.ref, Updates, []),
      State#state{write_buffer=[],
                  write_buffer_count=0}.
  
  -spec delete(binary(), hashtree()) -> hashtree().
  delete(Key, State) ->
  