anchor.diff:          if R =:= 0 -> P0;
              true -> (element(R, E))#item.p
           end,
  -      search(IO, X, Q, [{P, R} | Path])
  +      search_pageid(IO, X, Q, [{P, R} | Path])
     end.
   
   %%%_* Binary search within a page ==============================================
  
positive.code: 
  -record(page, % m == size(e)
          { pageid :: pageid()
          , p0 :: pageid_opt() % subtree with keys k' < (element(1, e))#item.k
          , e :: {#item{}}
          }).
  
  -record(btree,
          { order :: pos_integer() % aka N
          , root :: pageid_opt()
          }).
  
  %%%_* Creating an empty B-tree =================================================
  
negative.code: %%% Search and delete key X in B-tree A; if a page underflow is
  %%% necessary, balance with adjacent page if possible, otherwise merge;
  %%% return true if page A becomes undersize.
  delete(_Cache, _N, _X, ?NOPAGEID) ->
    ?dbg("delete(~p, ~p)~n", [_X, ?NOPAGEID]),
    false;
  delete(Cache1, N, X, APageId) ->
    {Cache2, A} = cache_read(Cache1, APageId),
    delete(Cache2, N, X, APageId, A).
  
  delete(Cache2, N, X, APageId, A = #page{p0 = AP0, e = AE}) ->
    ?dbg("delete(~p, ~p)~n", [X, A]),
    case binsearch(AE, X) of
      {found, K} ->
        %% found, now delete a^.e[k]
        R = K - 1,
        QPageId =
          if R =:= 0 -> AP0;
             true -> (element(R, AE))#item.p
          end,
        if QPageId =:= ?NOPAGEID ->
            %% a is a terminal page
            AE2 = erlang:delete_element(K, AE),
            Cache3 = cache_write(Cache2, A#page{e = AE2}),
            {Cache3, size(AE2) < N};
           true ->
            case del(Cache2, N, QPageId, APageId, K) of
              {Cache3, true} ->
                underflow(Cache3, N, APageId, QPageId, R);
              {Cache3, false} ->
                {Cache3, false}
            end
        end;
      {not_found, R} ->
        QPageId =
          if R =:= 0 -> AP0;
             true -> (element(R, AE))#item.p
          end,
        case delete(Cache2, N, X, QPageId) of
          {Cache3, true} ->
            underflow(Cache3, N, APageId, QPageId, R);
          {Cache3, false} ->
            {Cache3, false}
        end
    end.
  
  