anchor.diff:      Seedtree3_1 = seedtree_init(Fd3, RootPos3, 1),
       ?debugVal(Seedtree3_1),
       Seedtree3_2 = seedtree_insert_list(Seedtree3_1, Nodes3),
  -    {ok, Result3, Height3} = seedtree_write(
  +    {ok, Result3, Height3, HeightDiff3} = seedtree_write(
               Fd3, Seedtree3_2,
               TargetTreeHeight3 - Seedtree3_2#seedtree_root.height),
       ?debugVal(Result3),
  
positive.code:     ?assertEqual([[1],[2],[3],[4],[5]], Chunked7).
  
  
  bulk_load_test() ->
      Filename = "/tmp/bulk.bin",
      Fd = case couch_file:open(Filename, [create, overwrite]) of
      {ok, Fd2} ->
          Fd2;
      {error, _Reason} ->
          io:format("ERROR: Couldn't open file (~s) for tree storage~n",
                    [Filename])
      end,
  
      % Load the initial tree (with bulk operation)
      Nodes1 = lists:foldl(fun(I, Acc) ->
          {NodeId, {NodeMbr, NodeMeta, NodeData}} =
              vtree_test:random_node({I,27+I*329,45}),
          Node = {NodeMbr, NodeMeta, {[NodeId, <<"Bulk1">>], NodeData}},
          [Node|Acc]
      end, [], lists:seq(1,7)),
  
      {ok, Pos1, Height1} = bulk_load(Fd, 0, 0, Nodes1),
      ?debugVal(Pos1),
      ?assertEqual(2, Height1),
      {ok, Lookup1} = vtree:lookup(Fd, Pos1, {0,0,1001,1001}),
      ?assertEqual(7, length(Lookup1)),
      LeafDepths1 = vtreestats:leaf_depths(Fd, Pos1),
      ?assertEqual([1], LeafDepths1),
  
      % Load some more nodes
      Nodes2 = lists:foldl(fun(I, Acc) ->
          {NodeId, {NodeMbr, NodeMeta, NodeData}} =
              vtree_test:random_node({I,27+I*329,45}),
          Node = {NodeMbr, NodeMeta, {[NodeId, <<"Bulk1">>], NodeData}},
          [Node|Acc]
      end, [], lists:seq(1,20)),
  
      {ok, Pos2, Height2} = bulk_load(Fd, Pos1, Height1, Nodes2),
      ?debugVal(Pos2),
      ?assertEqual(4, Height2),
      {ok, Lookup2} = vtree:lookup(Fd, Pos2, {0,0,1001,1001}),
      ?assertEqual(27, length(Lookup2)),
      LeafDepths2 = vtreestats:leaf_depths(Fd, Pos2),
      ?assertEqual([3], LeafDepths2),
  
  
      % Load some more nodes to find a bug where the tree gets unbalanced
      BulkSize3 = [20, 100, 18],
      Results3 = lists:foldl(fun(Size, Acc2) ->
          {RootPos, RootHeight, _, _} = hd(Acc2),
          Nodes = lists:foldl(fun(I, Acc) ->
             {NodeId, {NodeMbr, NodeMeta, NodeData}} =
                  vtree_test:random_node({I,27+I*329,45}),
              Node = {NodeMbr, NodeMeta, {[NodeId, <<"Bulk1">>], NodeData}},
            [Node|Acc]
          end, [], lists:seq(1, Size)),
  
          {ok, Pos, Height} = bulk_load(Fd, RootPos, RootHeight, Nodes),
          ?debugVal(Pos),
          %?assertEqual(2, Height3),
          {ok, Lookup} = vtree:lookup(Fd, Pos, {0,0,1001,1001}),
          ?debugVal(length(Lookup)),
          %?assertEqual(14, length(Lookup2)),
          LeafDepths = vtreestats:leaf_depths(Fd, Pos),
          %?assertEqual([1], LeafDepths2),
          [{Pos, Height, LeafDepths, length(Lookup)}|Acc2]
      end, [{Pos2, Height2, [0], 0}], BulkSize3),
      ?debugVal(Results3),
      Results3_2 = [{H, Ld, Num} || {_, H, Ld, Num} <-
              tl(lists:reverse(Results3))],
      ?assertEqual([{4,[3],47},{6,[5],147},{6,[5],165}],Results3_2),
  
      BulkSize4 = [20, 17, 8, 64, 100],
      Results4 = lists:foldl(fun(Size, Acc2) ->
          {RootPos, RootHeight, _, _} = hd(Acc2),
          Nodes = lists:foldl(fun(I, Acc) ->
              {NodeId, {NodeMbr, NodeMeta, NodeData}} =
                  vtree_test:random_node({I,27+I*329,45}),
              Node = {NodeMbr, NodeMeta, {[NodeId, <<"Bulk1">>], NodeData}},
             [Node|Acc]
          end, [], lists:seq(1, Size)),
          {ok, Pos, Height} = bulk_load(Fd, RootPos, RootHeight, Nodes),
          %?debugVal(Pos),
          %?debugVal(Height),
          {ok, Lookup} = vtree:lookup(Fd, Pos, {0,0,1001,1001}),
          %?debugVal(length(Lookup)),
          LeafDepths = vtreestats:leaf_depths(Fd, Pos),
         [{Pos, Height, LeafDepths, length(Lookup)}|Acc2]
      end, [{Pos2, Height2, [0], 0}], BulkSize4),
      Results4_2 = [{H, Ld, Num} || {_, H, Ld, Num} <-
              tl(lists:reverse(Results4))],
      ?assertEqual([{4,[3],47},{4,[3],64},{4,[3],72},{5,[4],136},{6,[5],236}],
              Results4_2),
      ok.
  
  
  omt_load_test() ->
  
negative.code:     Seedtree4_1 = seedtree_init(Fd4, RootPos4, 3),
      ?debugVal(Seedtree4_1),
      Seedtree4_2 = seedtree_insert_list(Seedtree4_1, Nodes4),
      {ok, Result4, Height4, HeightDiff4} = seedtree_write(
              Fd4, Seedtree4_2,
              TargetTreeHeight4 - Seedtree4_2#seedtree_root.height),
      ?debugVal(Result4),
  