anchor.diff:      ok = eleveldb:put(Ref, HKey, Bin, []),
       State.
   
  -del_disk_bucket(Level, Bucket, State = #state{id = Id, ref = Ref}) ->
  -    HKey = encode_bucket(Id, Level, Bucket),
  -    ok = eleveldb:delete(Ref, HKey, []),
  -    State.
  +%% del_disk_bucket(Level, Bucket, State = #state{id = Id, ref = Ref}) ->
  +%%     HKey = encode_bucket(Id, Level, Bucket),
  +%%     ok = eleveldb:delete(Ref, HKey, []),
  +%%     State.
   
   -spec encode_id(binary() | non_neg_integer()) -> tree_id_bin().
   encode_id(TreeId) when is_integer(TreeId) ->
  
positive.code: -spec encode_bucket(tree_id_bin(), integer(), integer()) -> bucket_bin().
  encode_bucket(TreeId, Level, Bucket) ->
      <<$b,TreeId:22/binary,$b,Level:64/integer,Bucket:64/integer>>.
  
  -spec encode_meta(binary()) -> meta_bin().
  encode_meta(Key) ->
  
negative.code:                        %% gb_sets:to_list(Dirty),
                         bitarray_to_list(Dirty)
                 end,
      State2 = maybe_clear_buckets(NextRebuild, State),
      State3 = update_tree(Segments, State2),
      %% State2#state{dirty_segments=gb_sets:new()}
      State3#state{dirty_segments=bitarray_new(NumSegments),
                   next_rebuild=incremental}.
  
  %% Clear buckets if doing a full rebuild
  maybe_clear_buckets(full, State) ->
      clear_buckets(State);
  maybe_clear_buckets(incremental, State) ->
      State.
  
  %% Fold over the 'live' data (outside of the snapshot), removing all
  %% bucket entries for the tree.
  clear_buckets(State=#state{id=Id, ref=Ref}) ->
      Fun = fun({K,_V},Acc) ->
                    try
                        case decode_bucket(K) of
                            {Id, _, _} ->
                                eleveldb:delete(Ref, K, []),
                                Acc + 1;
                            _ ->
                                throw({break, Acc})
                        end
                    catch
                        _:_ -> % not a decodable bucket
                            throw({break, Acc})
                    end
            end,
      Opts = [{first_key, encode_bucket(Id, 0, 0)}],
      Removed = try
                    eleveldb:fold(Ref, Fun, 0, Opts)
                catch
                    {break, AccFinal} ->
                        AccFinal
                end,
      lager:debug("Tree ~p cleared ~p segments.\n", [Id, Removed]),
  
      %% Mark the tree as requiring a full rebuild (will be fixed
      %% reset at end of update_trees) AND dump the in-memory
      %% tree.
      State#state{next_rebuild = full,
                  tree = dict:new()}.
              
  
  -spec update_tree([integer()], hashtree()) -> hashtree().
  update_tree([], State) ->
  