anchor.diff:              [{{37,163,597,911},{node,inner},{seedtree_leaf,[3732,5606],[]}},
                {{27,984,226,986},{node,inner},{seedtree_leaf,[5039],[]}}]}]},[]},
           SeedTree2).
  -
  -% @doc Find the first node that encloses the input MBR completely at a certain
  -%     level. Return the the position relative to other children (starting
  -%     with 0).
  --spec find_enclosing(Fd::file:io_device(), RootPos::integer(),
  -        Level::integer(), InputMbr::list()) -> integer().
  -find_enclosing(Fd, RootPos, Level, InputMbr) ->
  -    ok.
  -
  -lookup_path_test() ->
  -    {ok, {RootPos, Fd}} = vtree_test:build_random_tree("/tmp/randtree.bin", 20),
  -    ?debugVal(RootPos),
  -    % Not inside 1st level
  -    EntryPath1 = lookup_path(Fd, RootPos, {1,3,2,4}, 2),
  -    ?assertEqual(-1, EntryPath1),
  -
  -    % Inside 1st level but not inside 2nd level
  -    EntryPath2 = lookup_path(Fd, RootPos, {19,120,950,510}, 2),
  -    ?assertEqual(-1, EntryPath2),
  -
  -    % Found in 2nd level
  -    EntryPath3 = lookup_path(Fd, RootPos, {542,356,698,513}, 2),
  -    ?assertEqual([0,0], EntryPath3),
  -    % Found in 3rd level (would also match [1,0,1], but we take the first
  -    % matching child)
  -    EntryPath4 = lookup_path(Fd, RootPos, {458,700,487,865}, 3),
  -    ?assertEqual([0,1,0], EntryPath4),
  -
  -    EntryPath5 = lookup_path(Fd, RootPos, {542,656,598,813}, 3),
  -    ?assertEqual([0,1,0], EntryPath5),
  -    EntryPath6 = lookup_path(Fd, RootPos, {42,456,698,512}, 3),
  -    ?assertEqual([0,0,2], EntryPath6),
  -    EntryPath7 = lookup_path(Fd, RootPos, {342,456,959,513}, 3),
  -    ?assertEqual([0,1,1], EntryPath7).
  -
  -
  -%find_enclosing_test() ->
  -%    {ok, {RootPos, _Fd}} = vtree_test:build_random_tree("/tmp/randtree.bin", 1000),
  -%    %?LOG_DEBUG(RootNode).
  -%    ?debugVal(RootPos).
  -
  -
  -%%%%%% Helpers %%%%
  -
  -% @doc Returns the ceiling of log_N(X)
  --spec log_n_ceil(N::integer(), X::integer()) -> integer().
  -log_n_ceil(N, X) ->
  -    ceiling(math:log(X) / math:log(N)).
  -
  -% From http://www.trapexit.org/Floating_Point_Rounding (2010-10-18)
  --spec ceiling(X::number()) -> integer().
  -ceiling(X) when X < 0 ->
  -    trunc(X);
  -ceiling(X) ->
  -    T = trunc(X),
  -    case X - T == 0 of
  -        true -> T;
  -        false -> T + 1
  -    end.
  -
  -% From http://www.trapexit.org/Floating_Point_Rounding (2010-10-18)
  --spec floor(X::number()) -> integer().
  -floor(X) when X < 0 ->
  -    T = trunc(X),
  -    case X - T == 0 of
  -        true -> T;
  -        false -> T - 1
  -    end;
  -floor(X) -> 
  -    trunc(X).
  -
  -% @doc split a list of elements into equally sized chunks (last element might
  -%     contain less elements)
  --spec chunk_list(List::list(), Size::integer()) -> [list()].
  -chunk_list(List, Size) when Size == 0 ->
  -    [List];
  -chunk_list(List, Size) ->
  -    chunk_list(List, Size, 0, [], []).
  -chunk_list([], _Size, _Cnt, Chunk, Result) when length(Chunk) > 0 ->
  -    lists:reverse([lists:reverse(Chunk)|Result]);
  -chunk_list([], _Size, _Cnt, _Chunk, Result) ->
  -    lists:reverse(Result);
  -chunk_list([H|T], Size, Cnt, Chunk, Result) when Cnt < Size ->
  -    chunk_list(T, Size, Cnt+1, [H|Chunk], Result);
  -chunk_list([H|T], Size, _Cnt, Chunk, Result) ->
  -    chunk_list(T, Size, 1, [H], [lists:reverse(Chunk)|Result]).
  -
  -% @doc split a list of elements into equally sized chunks (last element might
  -%     contain less elements). Applies Fun to every chunk and inserts the
  -%     return value of this function into the result list.
  --spec chunk_list(Fun::fun(), List::list(), Size::integer()) -> [list()].
  -chunk_list(_Fun, List, Size) when Size == 0 ->
  -    [List];
  -chunk_list(Fun, List, Size) ->
  -    chunk_list(Fun, List, Size, 0, [], []).
  -% List is processed, but some items are left in the last chunk
  -chunk_list(Fun, [], _Size, _Cnt, Chunk, Result) when length(Chunk) > 0 ->
  -    Entry = Fun(lists:reverse(Chunk)),
  -    %lists:reverse(Entry ++ Result);
  -    lists:reverse([Entry|Result]);
  -chunk_list(_Fun, [], _Size, _Cnt, _Chunk, Result) ->
  -    lists:reverse(Result);
  -chunk_list(Fun, [H|T], Size, Cnt, Chunk, Result) when Cnt < Size ->
  -    chunk_list(Fun, T, Size, Cnt+1, [H|Chunk], Result);
  -% Chunk is complete, add chunk to result
  -chunk_list(Fun, [H|T], Size, _Cnt, Chunk, Result) ->
  -    Entry = Fun(lists:reverse(Chunk)),
  -    %chunk_list(Fun, T, Size, 1, [H], Entry ++ Result).
  -    chunk_list(Fun, T, Size, 1, [H], [Entry|Result]).
  -
  -% XXX vmx: tests with function (check_list/6 ) are missing
  -chunk_list_test() ->
  -    List1 = [1,2,3,4,5],
  -    Chunked1 = chunk_list(List1, 2),
  -    ?assertEqual([[1,2],[3,4],[5]], Chunked1),
  -    Chunked2 = chunk_list(List1, 3),
  -    ?assertEqual([[1,2,3],[4,5]], Chunked2),
  -    Chunked3 = chunk_list(List1, 4),
  -    ?assertEqual([[1,2,3,4],[5]], Chunked3),
  -    Chunked4 = chunk_list(List1, 5),
  -    ?assertEqual([[1,2,3,4,5]], Chunked4),
  -    Chunked5 = chunk_list(List1, 6),
  -    ?assertEqual([[1,2,3,4,5]], Chunked5),
  -    Chunked6 = chunk_list(List1, 0),
  -    ?assertEqual([[1,2,3,4,5]], Chunked6),
  -    Chunked7 = chunk_list(List1, 1),
  -    ?assertEqual([[1],[2],[3],[4],[5]], Chunked7).
  
positive.code:             {{37,163,597,911},{node,inner},{seedtree_leaf,[3732,5606],[]}},
              {{27,984,226,986},{node,inner},{seedtree_leaf,[5039],[]}}]}]},
          SeedTree7Tree).
  %    SeedTree3 = lists:foldl(fun(I, STree) ->
  %        {NodeId, {NodeMbr, NodeMeta, NodeData}} =
  %            vtree_test:random_node({I,20,30}),
  %        Node = {NodeMbr, NodeMeta, {NodeId, NodeData}},
  %        seedtree_insert(STree, Node)
  %    end, SeedTree, lists:seq(1,100)),
  %    ?LOG_DEBUG(SeedTree3).
  
  % @doc Put an on disk tree into memory and prepare it to store new nodes in
  %     the leafs
  -spec seedtree(Fd::file:io_device(), RootPos::integer(),
          MaxDepth::integer()) -> seedtree_root().
  seedtree(Fd, RootPos, MaxDepth) ->
      Tree = seedtree(Fd, RootPos, MaxDepth, 0),
      #seedtree_root{tree=Tree}.
  -spec seedtree(Fd::file:io_device(), RootPos::integer(),
          MaxDepth::integer(), Depth::integer()) -> seedtree_node().
  seedtree(Fd, RootPos, MaxDepth, Depth) when Depth == MaxDepth ->
      {ok, Parent} = couch_file:pread_term(Fd, RootPos),
      {ParentMbr, ParentMeta, EntriesPos} = Parent,
      {ParentMbr, ParentMeta, #seedtree_leaf{orig=EntriesPos}};
  seedtree(Fd, RootPos, MaxDepth, Depth) ->
      {ok, Parent} = couch_file:pread_term(Fd, RootPos),
      {ParentMbr, ParentMeta, EntriesPos} = Parent,
      Children = lists:foldl(fun(EntryPos, Acc) ->
          Child = seedtree(Fd, EntryPos, MaxDepth, Depth+1),
          [Child|Acc]
      end, [], EntriesPos),
      {ParentMbr, ParentMeta, lists:reverse(Children)}.
  
  seedtree_test() ->
      {ok, {RootPos, Fd}} = vtree_test:build_random_tree("/tmp/randtree.bin", 20),
  
negative.code: -include_lib("eunit/include/eunit.hrl").
  
  -define(LOG_DEBUG(Msg), io:format(user, "DEBUG: ~p~n", [Msg])).
  
  % same as in vtree
  -record(node, {
      % type = inner | leaf
      type=leaf}).
  
  -record(seedtree_root, {
      tree = [] :: list(),
  