anchor.diff: --define(NODEBUG, true).
  -
  --include_lib("eunit/include/eunit.hrl").
  -
  --include_lib("../include/b_trees_templates.hrl").
  -
   %%
   %% %CopyrightBegin%
   %%
  
positive.code:                                                                                              _ ->
                                                                                                   lists:nth(KeyPos + 1, Subtrees)
                                                                                           end,
      ?debugFmt("wwe debugging delete_1_3 ===> ~n TreeXCLeft: ~p~n TreeX: ~p~n TreeXCRight: ~p~n", [_TreeXCLeft, TreeXC, _TreeXCRight]),
      Out = case KeyNoXC < SubtreeNoMin of
                true ->
                    if
                        KeyNoXCLeft >= SubtreeNoMin ->
                            % CLRS: case 3a - left
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3a - left  ~n", []),
  
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 1: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 2)]),
  
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 2.1: ~p~n", [KeyNoXCLeft]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 2.2: ~p~n", [KeyValuesXCLeft]),
  
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 2: ~p~n", [[lists:nth(KeyNoXCLeft, KeyValuesXCLeft)]]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues 3: ~p~n", [lists:sublist(KeyValues, KeyPos, KeyNo)]),
  
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 2) ++ [lists:nth(KeyNoXCLeft, KeyValuesXCLeft)] ++ lists:sublist(KeyValues, KeyPos, KeyNo)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [case SubtreeNo == 0 of
                                                                                                         true ->
                                                                                                             [];
                                                                                                         _ ->
                                                                                                             lists:sublist(Subtrees, 1, KeyPos - 2)
                                                                                                     end]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [case SubtreeNo == 0 of
                                                                                                         true ->
                                                                                                             [];
                                                                                                         _ ->
                                                                                                             lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
                                                                                                     end]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt KeyValues: ~p~n", [lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt Subtreest: ~p~n", [lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Del KeyValues: ~p~n", [[lists:nth(KeyPos - 1, KeyValues)] ++ lists:sublist(KeyValuesXC, 1, KeyNoXC)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXCLeft: ~p~n", [case SubtreeNoXCLeft == 0 of
                                                                                                        true ->
                                                                                                            [];
                                                                                                        _ ->
                                                                                                            lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)
                                                                                                    end]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXC: ~p~n", [SubtreesXC]),
                            {
                                KeyNo,
                                SubtreeNo,
                                    lists:sublist(KeyValues, 1, KeyPos - 2) ++ [lists:nth(KeyNoXCLeft, KeyValuesXCLeft)] ++ lists:sublist(KeyValues, KeyPos, KeyNo),
                                    lists:sublist(Subtrees, 1, KeyPos - 2) ++
                                    [{KeyNoXCLeft - 1, case SubtreeNoXCLeft == 0 of
                                                           true ->
                                                               0;
                                                           _ ->
                                                               SubtreeNoXCLeft - 1
                                                       end, lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1), case SubtreeNoXCLeft == 0 of
                                                                                                                    true ->
                                                                                                                        [];
                                                                                                                    _ ->
                                                                                                                        lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft)
                                                                                                                end
                                    },
                                        delete_1(Key, {KeyNoXC + 1, case SubtreeNoXC == 0 of
                                                                        true ->
                                                                            0;
                                                                        _ ->
                                                                            SubtreeNoXC + 1
                                                                    end, [lists:nth(KeyPos - 1, KeyValues)] ++ lists:sublist(KeyValuesXC, 1, KeyNoXC), case SubtreeNoXCLeft == 0 of
                                                                                                                                                           true ->
                                                                                                                                                               [];
                                                                                                                                                           _ ->
                                                                                                                                                               [lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)]
                                                                                                                                                       end ++ SubtreesXC}, SubtreeNoMin, KeyNoMax)
                                    ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
                            };
                        KeyNoXCRight >= SubtreeNoMin ->
                            % CLRS: case 3a - right
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3a - right ~n", []),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 1) ++ [lists:nth(1, KeyValuesXCRight)] ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 1)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Del KeyValues: ~p~n", [lists:sublist(KeyValuesXC, 1, KeyNoXC) ++ [lists:nth(KeyPos, KeyValues)]]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXC: ~p~n", [SubtreesXC]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Del SubtreesXCRight: ~p~n", [case SubtreeNoXCRight == 0 of
                                                                                                         true ->
                                                                                                             [];
                                                                                                         _ ->
                                                                                                             lists:nth(1, SubtreesXCRight)
                                                                                                     end]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt KeyValues: ~p~n", [lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight)]),
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n Nxt Subtreest: ~p~n", [case SubtreeNoXCRight == 0 of
                                                                                                   true ->
                                                                                                       [];
                                                                                                   _ ->
                                                                                                       lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight)
                                                                                               end]),
                            {
                                KeyNo,
                                SubtreeNo,
                                    lists:sublist(KeyValues, 1, KeyPos - 1) ++ [lists:nth(1, KeyValuesXCRight)] ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
                                    lists:sublist(Subtrees, 1, KeyPos - 1) ++
                                    [delete_1(Key, {KeyNoXC + 1, case SubtreeNoXC == 0 of
                                                                     true ->
                                                                         0;
                                                                     _ ->
                                                                         SubtreeNoXC + 1
                                                                 end, lists:sublist(KeyValuesXC, 1, KeyNoXC) ++ [lists:nth(KeyPos, KeyValues)], SubtreesXC ++ case SubtreeNoXCRight == 0 of
                                                                                                                                                                  true ->
                                                                                                                                                                      [];
                                                                                                                                                                  _ ->
                                                                                                                                                                      [lists:nth(1, SubtreesXCRight)]
                                                                                                                                                              end}, SubtreeNoMin, KeyNoMax),
                                        {KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of
                                                               true ->
                                                                   0;
                                                               _ ->
                                                                   SubtreeNoXCRight - 1
                                                           end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight == 0 of
                                                                                                                      true ->
                                                                                                                          [];
                                                                                                                      _ ->
                                                                                                                          lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight)
                                                                                                                  end
                                        }
                                    ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)
                            };
                        KeyNoXCRight == 0 ->
                            % CLRS: case 3b left
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3b left  ~n", []),
                            case KeyNo == 1 of
                                true ->
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [SubtreesXCLeft]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [SubtreesXC]),
                                    delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, SubtreeNoXCLeft + SubtreeNoXC, KeyValuesXCLeft ++ KeyValues ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax);
                                _ ->
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 2) ++ lists:sublist(KeyValues, KeyPos, KeyNo)]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 2)]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner KeyValues: ~p~n", [KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 1: ~p~n", [SubtreesXCLeft]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 3: ~p~n", [SubtreesXC]),
                                    {
                                        KeyNo - 1,
                                        SubtreeNo - 1,
                                            lists:sublist(KeyValues, 1, KeyPos - 2) ++ lists:sublist(KeyValues, KeyPos, KeyNo),
                                            lists:sublist(Subtrees, 1, KeyPos - 2) ++
                                            [
                                                delete_1(Key, {KeyNoXCLeft + KeyNoXC + 1, case SubtreeNoXC == 0 of
                                                                                              true ->
                                                                                                  0;
                                                                                              _ ->
                                                                                                  SubtreeNoXCLeft + SubtreeNoXC
                                                                                          end, KeyValuesXCLeft ++ [lists:nth(KeyPos - 1, KeyValues)] ++ KeyValuesXC, SubtreesXCLeft ++ SubtreesXC}, SubtreeNoMin, KeyNoMax)
                                            ] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
                                    }
                            end;
                        true ->
                            % CLRS: case 3b right
                            ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3b right ~n", []),
                            case KeyNo == 1 of
                                true ->
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [KeyValuesXC ++ KeyValues ++ KeyValuesXCRight]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [SubtreesXC]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [SubtreesXCRight]),
                                    delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, SubtreeNoXC + SubtreeNoXCRight, KeyValuesXC ++ KeyValues ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax);
                                _ ->
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer KeyValues: ~p~n", [lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo)]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 1)]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Outer Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner KeyValues: ~p~n", [KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 1: ~p~n", [SubtreesXC]),
                                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Inner Subtrees Part 3: ~p~n", [SubtreesXCRight]),
                                    {
                                        KeyNo - 1,
                                        SubtreeNo - 1,
                                            lists:sublist(KeyValues, 1, KeyPos - 1) ++ lists:sublist(KeyValues, KeyPos + 1, KeyNo),
                                            lists:sublist(Subtrees, 1, KeyPos - 1) ++
                                            [
                                                delete_1(Key, {KeyNoXC + KeyNoXCRight + 1, case SubtreeNoXC == 0 of
                                                                                               true ->
                                                                                                   0;
                                                                                               _ ->
                                                                                                   SubtreeNoXC + SubtreeNoXCRight
                                                                                           end, KeyValuesXC ++ [lists:nth(KeyPos, KeyValues)] ++ KeyValuesXCRight, SubtreesXC ++ SubtreesXCRight}, SubtreeNoMin, KeyNoMax)
                                            ] ++ lists:sublist(Subtrees, KeyPos + 2, SubtreeNo)
                                    }
                            end
                    end;
                _ ->
                    % CLRS: case 3 else
                    ?debugFmt("wwe debugging delete_1_3 ===> ~n CLRS: case 3 else ~n", []),
                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New KeyValues: ~p~n", [KeyValues]),
                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 1: ~p~n", [lists:sublist(Subtrees, 1, KeyPos - 1)]),
                    ?debugFmt("wwe debugging delete_1_3 ===> ~n New Subtrees Part 3: ~p~n", [lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)]),
                    {
                        KeyNo,
                        SubtreeNo,
                        KeyValues,
                            lists:sublist(Subtrees, 1, KeyPos - 1) ++ [delete_1(Key, TreeXC, SubtreeNoMin, KeyNoMax)] ++ lists:sublist(Subtrees, KeyPos + 1, SubtreeNo)
                    }
            end,
      ?debugFmt("wwe debugging delete_1_3 ===> Start ~n Out: ~p~n", [Out]),
      Out.
  
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  
  
negative.code:         []
      };
  combine({LeftKeyNo, LeftSubtreeNo, LeftKeyValues, LeftSubtrees} = _LeftTree, {RightKeyNo, RightSubtreeNo, RightKeyValues, RightSubtrees} = _RightTree) ->
      {
          LeftKeyNo + RightKeyNo,
          LeftSubtreeNo + RightSubtreeNo - 1,
  