anchor.diff:  %%      ""wrapping around", i.e. its begin is larger than its end.
   %%      Returns the chunk and the remaining interval for which the DB may still
   %%      have data (a subset of I).
  -%%      Precond: Interval is a subset of the range of the dht_node and thus, in
  -%%      particular, continuous
  --spec get_chunk(DB::db(), Interval::intervals:interval(), ChunkSize::pos_integer()) ->
  -    {intervals:interval(), db_as_list()}.
  -get_chunk(DB, Interval, ChunkSize) -> get_chunk_(DB, Interval, ChunkSize).
  -
  --spec get_chunk_(DB::db_t(), Interval::intervals:interval(), ChunkSize::pos_integer()) ->
  -    {intervals:interval(), db_as_list()}.
  -get_chunk_({ETSDB, _Subscr} = DB, Interval, ChunkSize) ->
  +%%      Precond: Interval is a subset of the range of the dht_node and continuous!
  +-spec get_chunk(DB::db(), Interval::intervals:interval(), ChunkSize::pos_integer() | all)
  +        -> {intervals:interval(), db_as_list()}.
  +get_chunk(DB, Interval, ChunkSize) ->
  +    get_chunk_(DB, Interval, fun(_) -> true end, fun(E) -> E end, ChunkSize).
  +
  +%% @doc Returns all ValueFun(DBEntry) objects of the given DB which are in the
  +%%      given interval and satisfy FilterFun but at most ChunkSize elements.
  +%%      See get_chunk/3 for more details.
  +-spec get_chunk(DB::db(), Interval::intervals:interval(),
  +                FilterFun::fun((db_entry:entry()) -> boolean()),
  +                ValueFun::fun((db_entry:entry()) -> V), ChunkSize::pos_integer() | all)
  +        -> {intervals:interval(), [V]}.
  +get_chunk(DB, Interval, FilterFun, ValueFun, ChunkSize) ->
  +    get_chunk_(DB, Interval, FilterFun, ValueFun, ChunkSize).
  +
  +-spec get_chunk_(DB::db_t(), Interval::intervals:interval(),
  +                 FilterFun::fun((db_entry:entry()) -> boolean()),
  +                 ValueFun::fun((db_entry:entry()) -> V), ChunkSize::pos_integer() | all) ->
  +    {intervals:interval(), [V]}.
  +get_chunk_(DB, Interval, FilterFun, ValueFun, all) ->
  +    get_chunk_(DB, Interval, FilterFun, ValueFun, get_load_(DB));
  +get_chunk_({ETSDB, _Subscr} = DB, Interval, FilterFun, ValueFun, ChunkSize) ->
       % assert ChunkSize > 0, see ChunkSize type
       case get_load_(DB) of
           0 -> {intervals:empty(), []};
  
positive.code: %% pre: Current is in ets table, ets table is not empty
  -spec get_chunk_inner(DB::db_t(), Current::?RT:key() | '$end_of_table',
                        RealStart::?RT:key(), Interval::intervals:interval(),
                        ChunkSize::pos_integer(), Chunk::db_as_list())
          -> {?RT:key() | '$end_of_table' | '$end_of_interval', db_as_list()}.
  get_chunk_inner(_DB, RealStart, RealStart, _Interval, _ChunkSize, Chunk) ->
      %ct:pal("inner: 0: ~p", [RealStart]),
      % we hit the start element, i.e. our whole data set has been traversed
      {'$end_of_interval', Chunk};
  get_chunk_inner(_DB, Current, _RealStart, _Interval, 0, Chunk) ->
      %ct:pal("inner: 1: ~p", [Current]),
      % we hit the chunk size limit
      {Current, Chunk};
  get_chunk_inner({ETSDB, _Subscr} = DB, '$end_of_table', RealStart, Interval, ChunkSize, Chunk) ->
      %ct:pal("inner: 2: ~p", ['$end_of_table']),
      % reached end of table - start at beginning (may be a wrapping interval)
      get_chunk_inner(DB, ets:first(ETSDB), RealStart, Interval, ChunkSize, Chunk);
  get_chunk_inner({ETSDB, _Subscr} = DB, Current, RealStart, Interval, ChunkSize, Chunk) ->
      %ct:pal("inner: 3: ~p", [Current]),
      case intervals:in(Current, Interval) of
          true ->
              Entry = get_entry_(DB, Current),
              Next = ets:next(ETSDB, Current),
              get_chunk_inner(DB, Next, RealStart, Interval, ChunkSize - 1, [Entry | Chunk]);
          _ ->
              {'$end_of_interval', Chunk}
      end.
  
negative.code:                     {intervals:empty(), []};
                  FirstKey ->
                      %ct:pal("first key: ~.0p~n", [FirstKey]),
                      FirstEntry = get_entry_(DB, FirstKey),
                      Chunk0 = case FilterFun(FirstEntry) of
                                   true -> [ValueFun(FirstEntry)];
                                   _    -> []
                               end,
                      {Next, Chunk} =
                          get_chunk_inner(DB, ets:next(ETSDB, FirstKey), FirstKey,
                                          Interval, FilterFun, ValueFun, ChunkSize - 1, Chunk0),
                      case Next of
                          '$end_of_table' ->
                              {intervals:empty(), Chunk};
  