diff --git a/src/b_trees.erl b/src/b_trees.erl index b24ef03..13b0cdb 100644 --- a/src/b_trees.erl +++ b/src/b_trees.erl @@ -316,8 +316,8 @@ delete(Key, {SubtreeNoMin, KeyNoMax, SizeKeyValues, SortFunction, State, {KeyNo, none -> erlang:error({key_not_found, Key}); _ -> - {SubtreeNoMin, KeyNoMax, SizeKeyValues - 1, SortFunction, State, case KeyNo == 1 of - true -> + {SubtreeNoMin, KeyNoMax, SizeKeyValues - 1, SortFunction, State, case KeyNo of + 1 -> nil; _ -> { @@ -431,13 +431,13 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, lists:sublist(Subtrees, 1, KeyPos - 1), [ { - KeyNoXC - 1, case SubtreeNoXC == 0 of - true -> + KeyNoXC - 1, case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC - 1 - end, lists:sublist(KeyValuesXC, 1, KeyNoXC - 1), case SubtreeNoXC == 0 of - true -> + end, lists:sublist(KeyValuesXC, 1, KeyNoXC - 1), case SubtreeNoXC of + 0 -> []; _ -> lists:sublist(SubtreesXC, 1, KeyNoXC) @@ -447,8 +447,8 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, KeyNoXCRight, SubtreeNoXCRight, KeyValuesXCRight, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> []; _ -> lists:append([ @@ -480,8 +480,8 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, KeyNoXC, SubtreeNoXC, KeyValuesXC, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> []; _ -> lists:append([ @@ -491,13 +491,13 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, end }, { - KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of - true -> + KeyNoXCRight - 1, case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXCRight - 1 - end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight == 0 of - true -> + end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight of + 0 -> []; _ -> lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight) @@ -512,8 +512,8 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, { LeftTree, RightTree - } = case SubtreeNoXC == 0 of - true -> + } = case SubtreeNoXC of + 0 -> { {0, 0, [], []}, {0, 0, [], []} @@ -524,12 +524,12 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, lists:nth(1, SubtreesXCRight) } end, - case KeyNo == 1 of - true -> + case KeyNo of + 1 -> { KeyNoXC + KeyNoXCRight, - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXC + SubtreeNoXCRight - 1 @@ -538,8 +538,8 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, KeyValuesXC, KeyValuesXCRight ]), - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> []; _ -> lists:append([ @@ -560,8 +560,8 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, lists:append([ lists:sublist(Subtrees, 1, KeyPos - 1), [{ - KeyNoXC + KeyNoXCRight, case SubtreeNoXCRight == 0 of - true -> + KeyNoXC + KeyNoXCRight, case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXC + SubtreeNoXCRight - 1 @@ -569,8 +569,8 @@ delete_1_2(_, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, _, KeyPos, KeyValuesXC, KeyValuesXCRight ]), - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> []; _ -> lists:append([ @@ -612,13 +612,13 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi lists:append([ lists:sublist(Subtrees, 1, KeyPos - 1), [{ - KeyNoXC - 1, case SubtreeNoXC == 0 of - true -> + KeyNoXC - 1, case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC - 1 - end, lists:sublist(KeyValuesXC, 1, KeyNoXC - 1), case SubtreeNoXC == 0 of - true -> + end, lists:sublist(KeyValuesXC, 1, KeyNoXC - 1), case SubtreeNoXC of + 0 -> []; _ -> lists:sublist(SubtreesXC, 1, KeyNoXC) @@ -628,8 +628,8 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi KeyNoXCRight, SubtreeNoXCRight, KeyValuesXCRight, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> []; _ -> InsertFunction( @@ -665,8 +665,8 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi KeyNoXC, SubtreeNoXC, KeyValuesXC, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> []; _ -> InsertFunction( @@ -679,13 +679,13 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi end }, { - KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of - true -> + KeyNoXCRight - 1, case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXCRight - 1 - end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight == 0 of - true -> + end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight of + 0 -> []; _ -> InsertFunction( @@ -703,8 +703,8 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi { LeftTree, RightTree - } = case SubtreeNoXC == 0 of - true -> + } = case SubtreeNoXC of + 0 -> { {0, 0, [], []}, {0, 0, [], []} @@ -715,12 +715,12 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi lists:nth(1, SubtreesXCRight) } end, - case KeyNo == 1 of - true -> + case KeyNo of + 1 -> { KeyNoXC + KeyNoXCRight, - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXC + SubtreeNoXCRight - 1 @@ -729,8 +729,8 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi KeyValuesXC, KeyValuesXCRight ]), - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> []; _ -> InsertFunction( @@ -757,15 +757,15 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi lists:append([ lists:sublist(Subtrees, 1, KeyPos - 1), [{ - KeyNoXC + KeyNoXCRight, case SubtreeNoXCRight == 0 of - true -> + KeyNoXC + KeyNoXCRight, case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXC + SubtreeNoXCRight - 1 end, lists:append([KeyValuesXC, KeyValuesXCRight - ]), case SubtreeNoXCRight == 0 of - true -> + ]), case SubtreeNoXCRight of + 0 -> []; _ -> InsertFunction( @@ -788,15 +788,15 @@ delete_1_2(_Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMi -spec delete_1_3(key(), subtree(), pos_integer(), pos_integer(), pos_integer(), sort_function(), state()) -> subtree(). delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyPos, SortFunction, nil) -> - {KeyNoXCLeft, SubtreeNoXCLeft, KeyValuesXCLeft, SubtreesXCLeft} = case KeyPos == 1 of - true -> + {KeyNoXCLeft, SubtreeNoXCLeft, KeyValuesXCLeft, SubtreesXCLeft} = case KeyPos of + 1 -> {0, 0, [], []}; _ -> lists:nth(KeyPos - 1, Subtrees) end, {KeyNoXC, SubtreeNoXC, KeyValuesXC, SubtreesXC} = TreeXC = lists:nth(KeyPos, Subtrees), - {KeyNoXCRight, SubtreeNoXCRight, KeyValuesXCRight, SubtreesXCRight} = case KeyPos == SubtreeNo of - true -> + {KeyNoXCRight, SubtreeNoXCRight, KeyValuesXCRight, SubtreesXCRight} = case KeyPos of + SubtreeNo -> {0, 0, [], []}; _ -> lists:nth(KeyPos + 1, Subtrees) @@ -816,13 +816,13 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, ]), lists:append([ lists:sublist(Subtrees, 1, KeyPos - 2), - [{KeyNoXCLeft - 1, case SubtreeNoXCLeft == 0 of - true -> + [{KeyNoXCLeft - 1, case SubtreeNoXCLeft of + 0 -> 0; _ -> SubtreeNoXCLeft - 1 - end, lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1), case SubtreeNoXCLeft == 0 of - true -> + end, lists:sublist(KeyValuesXCLeft, 1, KeyNoXCLeft - 1), case SubtreeNoXCLeft of + 0 -> []; _ -> lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft) @@ -832,8 +832,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, Key, { KeyNoXC + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC + 1 @@ -843,8 +843,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, lists:sublist(KeyValuesXC, 1, KeyNoXC) ]), lists:append([ - case SubtreeNoXCLeft == 0 of - true -> + case SubtreeNoXCLeft of + 0 -> []; _ -> [lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)] @@ -876,8 +876,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, Key, { KeyNoXC + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC + 1 @@ -888,8 +888,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, ]), lists:append([ SubtreesXC, - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> []; _ -> [lists:nth(1, SubtreesXCRight)] @@ -900,13 +900,13 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, KeyNoMax, SortFunction, nil), - {KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of - true -> + {KeyNoXCRight - 1, case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXCRight - 1 - end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight == 0 of - true -> + end, lists:sublist(KeyValuesXCRight, 2, KeyNoXCRight), case SubtreeNoXCRight of + 0 -> []; _ -> lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight) @@ -918,8 +918,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, }; KeyNoXCRight == 0 -> % CLRS: case 3b left - case KeyNo == 1 of - true -> + case KeyNo of + 1 -> delete_1( Key, { @@ -953,8 +953,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, Key, { KeyNoXCLeft + KeyNoXC + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXCLeft + SubtreeNoXC @@ -977,8 +977,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, end; true -> % CLRS: case 3b right - case KeyNo == 1 of - true -> + case KeyNo of + 1 -> delete_1( Key, { @@ -1014,8 +1014,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, Key, { KeyNoXC + KeyNoXCRight + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC + SubtreeNoXCRight @@ -1056,8 +1056,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNoMin, KeyNoMax, delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin, KeyNoMax, KeyPos, SortFunction, {StateTarget, DeleteFunction, InsertFunction, LookupFunction} = State) -> Subtrees = LookupFunction(StateTarget, lookup, SubtreesKey), true = DeleteFunction(StateTarget, delete, SubtreesKey), - {KeyNoXCLeft, SubtreeNoXCLeft, KeyValuesXCLeft, SubtreesKeyXCLeft} = case KeyPos == 1 of - true -> + {KeyNoXCLeft, SubtreeNoXCLeft, KeyValuesXCLeft, SubtreesKeyXCLeft} = case KeyPos of + 1 -> {0, 0, [], []}; _ -> lists:nth(KeyPos - 1, Subtrees) @@ -1065,8 +1065,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin SubtreesXCLeft = LookupFunction(StateTarget, lookup, SubtreesKeyXCLeft), {KeyNoXC, SubtreeNoXC, KeyValuesXC, SubtreesKeyXC} = TreeXC = lists:nth(KeyPos, Subtrees), SubtreesXC = LookupFunction(StateTarget, lookup, SubtreesKeyXC), - {KeyNoXCRight, SubtreeNoXCRight, KeyValuesXCRight, SubtreesKeyXCRight} = case KeyPos == SubtreeNo of - true -> + {KeyNoXCRight, SubtreeNoXCRight, KeyValuesXCRight, SubtreesKeyXCRight} = case KeyPos of + SubtreeNo -> {0, 0, [], []}; _ -> lists:nth(KeyPos + 1, Subtrees) @@ -1092,8 +1092,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin insert, lists:append([ lists:sublist(Subtrees, 1, KeyPos - 2), - [{KeyNoXCLeft - 1, case SubtreeNoXCLeft == 0 of - true -> + [{KeyNoXCLeft - 1, case SubtreeNoXCLeft of + 0 -> 0; _ -> SubtreeNoXCLeft - 1 @@ -1101,8 +1101,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin InsertFunction( StateTarget, insert, - case SubtreeNoXCLeft == 0 of - true -> + case SubtreeNoXCLeft of + 0 -> []; _ -> lists:sublist(SubtreesXCLeft, 1, KeyNoXCLeft) @@ -1112,8 +1112,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin Key, { KeyNoXC + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC + 1 @@ -1126,8 +1126,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin StateTarget, insert, lists:append([ - case SubtreeNoXCLeft == 0 of - true -> + case SubtreeNoXCLeft of + 0 -> []; _ -> [lists:nth(SubtreeNoXCLeft, SubtreesXCLeft)] @@ -1160,8 +1160,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin Key, { KeyNoXC + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC + 1 @@ -1175,16 +1175,16 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin insert, lists:append([ SubtreesXC, - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> []; _ -> [lists:nth(1, SubtreesXCRight)] end ])) }, SubtreeNoMin, KeyNoMax, SortFunction, State), - {KeyNoXCRight - 1, case SubtreeNoXCRight == 0 of - true -> + {KeyNoXCRight - 1, case SubtreeNoXCRight of + 0 -> 0; _ -> SubtreeNoXCRight - 1 @@ -1192,8 +1192,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin InsertFunction( StateTarget, insert, - case SubtreeNoXCRight == 0 of - true -> + case SubtreeNoXCRight of + 0 -> []; _ -> lists:sublist(SubtreesXCRight, 2, SubtreeNoXCRight) @@ -1207,8 +1207,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin % CLRS: case 3b left true = DeleteFunction(StateTarget, delete, SubtreesKeyXCLeft), true = DeleteFunction(StateTarget, delete, SubtreesKeyXC), - case KeyNo == 1 of - true -> + case KeyNo of + 1 -> delete_1( Key, { @@ -1246,8 +1246,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin Key, { KeyNoXCLeft + KeyNoXC + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXCLeft + SubtreeNoXC @@ -1274,8 +1274,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin % CLRS: case 3b right true = DeleteFunction(StateTarget, delete, SubtreesKeyXC), true = DeleteFunction(StateTarget, delete, SubtreesKeyXCRight), - case KeyNo == 1 of - true -> + case KeyNo of + 1 -> delete_1( Key, { @@ -1314,8 +1314,8 @@ delete_1_3(Key, {KeyNo, SubtreeNo, KeyValues, SubtreesKey} = _Tree, SubtreeNoMin Key, { KeyNoXC + KeyNoXCRight + 1, - case SubtreeNoXC == 0 of - true -> + case SubtreeNoXC of + 0 -> 0; _ -> SubtreeNoXC + SubtreeNoXCRight @@ -1432,8 +1432,7 @@ from_dict_1([{Key, Value} | Tail], BTree) -> get(Key, {_, _, 0, _, _, nil}) -> erlang:error({key_not_found, Key}); get(Key, {_, _, _, SortFunction, State, Tree}) -> - case lookup_1(Key, Tree, SortFunction, State) - of + case lookup_1(Key, Tree, SortFunction, State) of {value, Value} -> Value; _ -> @@ -1488,9 +1487,9 @@ insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, Subtrees}, SubtreeNo none -> % Look ahead. {SubtreeKeyNo, _, SubtreeKeyValues, _} = Subtree = lists:nth(SubtreePos, Subtrees), - case SubtreeKeyNo == KeyNoMax of + case SubtreeKeyNo of % Split node. - true -> + KeyNoMax -> {SplitKeyValues, SplitSubtrees1, SplitTree1, SplitTree2, SplitSubtrees2} = split_node_non_root(KeyNo, KeyValues, Subtrees, Subtree, SubtreePos, SubtreeNoMin, SortFunction, nil), { KeyNo + 1, @@ -1537,9 +1536,9 @@ insert_1({Key, _} = KeyValue, {KeyNo, SubtreeNo, KeyValues, SubtreesKey}, Subtre none -> % Look ahead. {SubtreeKeyNo, _, SubtreeKeyValues, _} = Subtree = lists:nth(SubtreePos, Subtrees), - case SubtreeKeyNo == KeyNoMax of + case SubtreeKeyNo of % Split node. - true -> + KeyNoMax -> {SplitKeyValues, SplitSubtrees1, SplitTree1, SplitTree2, SplitSubtrees2} = split_node_non_root(KeyNo, KeyValues, Subtrees, Subtree, SubtreePos, SubtreeNoMin, SortFunction, State), { KeyNo + 1, @@ -1610,16 +1609,16 @@ split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeK % SplitTree 1 .......................................................... { SubtreeNoMin - 1, - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> 0; _ -> SubtreeNoMin end, lists:sublist(TreeKeyValues, 1, SubtreeNoMin - 1), % Leaf node to be splitted ? - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> []; _ -> lists:sublist(TreeSubtrees, 1, SubtreeNoMin) @@ -1628,16 +1627,16 @@ split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeK % SplitTree 2 .......................................................... { TreeKeyNo - SubtreeNoMin, - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> 0; _ -> TreeKeyNo - SubtreeNoMin + 1 end, lists:sublist(TreeKeyValues, SubtreeNoMin + 1, TreeKeyNo), % Leaf node to be splitted ? - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> []; _ -> lists:sublist(TreeSubtrees, SubtreeNoMin + 1, TreeKeyNo + 1) @@ -1657,16 +1656,16 @@ split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeK % SplitTree 1 .......................................................... { SubtreeNoMin - 1, - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> 0; _ -> SubtreeNoMin end, lists:sublist(TreeKeyValues, 1, SubtreeNoMin - 1), % Leaf node to be splitted ? - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> []; _ -> InsertFunction( @@ -1678,16 +1677,16 @@ split_node_non_root(KeyNo, KeyValues, Subtrees, {TreeKeyNo, TreeSubtreeNo, TreeK % SplitTree 2 .......................................................... { TreeKeyNo - SubtreeNoMin, - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> 0; _ -> TreeKeyNo - SubtreeNoMin + 1 end, lists:sublist(TreeKeyValues, SubtreeNoMin + 1, TreeKeyNo), % Leaf node to be splitted ? - case TreeSubtreeNo == 0 of - true -> + case TreeSubtreeNo of + 0 -> []; _ -> InsertFunction( @@ -1807,8 +1806,8 @@ split_node_root({KeyNo, SubtreeNo, KeyValues, SubtreesKey}, SubtreeNoMin, {State is_defined(_, {_, _, 0, _, _, nil}) -> false; is_defined(Key, {_, _, _, SortFunction, State, Tree}) -> - case lookup_1(Key, Tree, SortFunction, State) == none of - true -> + case lookup_1(Key, Tree, SortFunction, State) of + none -> false; _ -> true @@ -2395,8 +2394,8 @@ binary_search(Key, KeyValues, KeyNo, Lower, Upper, SortFunction) -> % Leaf node. lookup_1(Key, {KeyNo, 0, KeyValues, []}, SortFunction, _) -> {Value, _} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), - case Value == none of - true -> + case Value of + none -> Value; _ -> {value, Value} @@ -2404,16 +2403,16 @@ lookup_1(Key, {KeyNo, 0, KeyValues, []}, SortFunction, _) -> % Non-Leaf node. lookup_1(Key, {KeyNo, _, KeyValues, Subtrees}, SortFunction, nil) -> {Value, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), - case Value == none of - true -> + case Value of + none -> lookup_1(Key, lists:nth(Pos, Subtrees), SortFunction, nil); _ -> {value, Value} end; lookup_1(Key, {KeyNo, _, KeyValues, SubtreesKey}, SortFunction, {StateTarget, _, _, LookupFunction} = State) -> {Value, Pos} = binary_search(Key, KeyValues, KeyNo, 1, KeyNo, SortFunction), - case Value == none of - true -> + case Value of + none -> lookup_1(Key, lists:nth(Pos, LookupFunction(StateTarget, lookup, SubtreesKey)), SortFunction, State); _ -> {value, Value} diff --git a/src/b_trees_test.erl b/src/b_trees_test.erl index 6f278dd..98a648e 100644 --- a/src/b_trees_test.erl +++ b/src/b_trees_test.erl @@ -32,8 +32,8 @@ copy_test() -> {ok, _} = dets:open_file(b_tree_4_dets, [{file, ?DIRECTORY_DETS ++ "b_tree_4_dets"}]), {ok, _} = dets:open_file(b_tree_4_dets_empty, [{file, ?DIRECTORY_DETS ++ "b_tree_4_dets_empty"}]), - case ok == mnesia:create_schema([node()]) of - true -> + case mnesia:create_schema([node()]) of + ok -> ok; _ -> ok = mnesia:delete_schema([node()]),