diff options
author | Noah Slater <nslater@apache.org> | 2009-07-06 00:33:50 +0000 |
---|---|---|
committer | Noah Slater <nslater@apache.org> | 2009-07-06 00:33:50 +0000 |
commit | 282b96ddd9a84b740788c2358ec0f5fedafb7cc6 (patch) | |
tree | fb48e605ceb8079d0195d3b1ec0eca7110fa7ef2 /src/couchdb/couch_key_tree.erl | |
parent | b5cc085d3bc6316063f14adedf20632ee904875d (diff) |
trimmed trailing whitespace
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@791350 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/couchdb/couch_key_tree.erl')
-rw-r--r-- | src/couchdb/couch_key_tree.erl | 46 |
1 files changed, 23 insertions, 23 deletions
diff --git a/src/couchdb/couch_key_tree.erl b/src/couchdb/couch_key_tree.erl index d08f5ede..3177087d 100644 --- a/src/couchdb/couch_key_tree.erl +++ b/src/couchdb/couch_key_tree.erl @@ -26,14 +26,14 @@ % partial trees arranged by how much they are cut off. merge(A, B) -> - {Merged, HasConflicts} = + {Merged, HasConflicts} = lists:foldl( fun(InsertTree, {AccTrees, AccConflicts}) -> {ok, Merged, Conflicts} = merge_one(AccTrees, InsertTree, [], false), {Merged, Conflicts or AccConflicts} end, {A, false}, B), - if HasConflicts or + if HasConflicts or ((length(Merged) /= length(A)) and (length(Merged) /= length(B))) -> Conflicts = conflicts; true -> @@ -61,7 +61,7 @@ merge_one([{Start, Tree}|Rest], {StartInsert, TreeInsert}, OutAcc, ConflictsAcc) no -> merge_one(Rest, {StartB, TreeB}, [{StartA, TreeA} | OutAcc], ConflictsAcc) end. - + merge_at([], _Place, _Insert) -> no; merge_at([{Key, Value, SubTree}|Sibs], 0, {InsertKey, InsertValue, InsertSubTree}) -> @@ -120,7 +120,7 @@ find_missing([{Start, {Key, Value, SubTree}} | RestTree], SeachKeys) -> ImpossibleKeys = [{KeyPos, KeyValue} || {KeyPos, KeyValue} <- SeachKeys, KeyPos < Start], Missing = find_missing_simple(Start, [{Key, Value, SubTree}], PossibleKeys), find_missing(RestTree, ImpossibleKeys ++ Missing). - + find_missing_simple(_Pos, _Tree, []) -> []; find_missing_simple(_Pos, [], SeachKeys) -> @@ -128,7 +128,7 @@ find_missing_simple(_Pos, [], SeachKeys) -> find_missing_simple(Pos, [{Key, _, SubTree} | RestTree], SeachKeys) -> PossibleKeys = [{KeyPos, KeyValue} || {KeyPos, KeyValue} <- SeachKeys, KeyPos >= Pos], ImpossibleKeys = [{KeyPos, KeyValue} || {KeyPos, KeyValue} <- SeachKeys, KeyPos < Pos], - + SrcKeys2 = PossibleKeys -- [{Pos, Key}], SrcKeys3 = find_missing_simple(Pos + 1, SubTree, SrcKeys2), ImpossibleKeys ++ find_missing_simple(Pos, RestTree, SrcKeys3). @@ -145,15 +145,15 @@ filter_leafs([{Pos, [{LeafKey, _}|_]} = Path |Rest], Keys, FilteredAcc, RemovedK % this did match a key, remove both the node and the input key filter_leafs(Rest, FilteredKeys, FilteredAcc, [{Pos, LeafKey} | RemovedKeysAcc]) end. - + % Removes any branches from the tree whose leaf node(s) are in the Keys remove_leafs(Trees, Keys) -> % flatten each branch in a tree into a tree path Paths = get_all_leafs_full(Trees), - + % filter out any that are in the keys list. {FilteredPaths, RemovedKeys} = filter_leafs(Paths, Keys, [], []), - + % convert paths back to trees NewTree = lists:foldl( fun({PathPos, Path},TreeAcc) -> @@ -170,7 +170,7 @@ remove_leafs(Trees, Keys) -> % are returned. get_key_leafs(Tree, Keys) -> get_key_leafs(Tree, Keys, []). - + get_key_leafs(_, [], Acc) -> {Acc, []}; get_key_leafs([], Keys, Acc) -> @@ -178,14 +178,14 @@ get_key_leafs([], Keys, Acc) -> get_key_leafs([{Pos, Tree}|Rest], Keys, Acc) -> {Gotten, RemainingKeys} = get_key_leafs_simple(Pos, [Tree], Keys, []), get_key_leafs(Rest, RemainingKeys, Gotten ++ Acc). - + get_key_leafs_simple(_Pos, _Tree, [], _KeyPathAcc) -> {[], []}; get_key_leafs_simple(_Pos, [], KeysToGet, _KeyPathAcc) -> {[], KeysToGet}; get_key_leafs_simple(Pos, [{Key, _Value, SubTree}=Tree | RestTree], KeysToGet, KeyPathAcc) -> case lists:delete({Pos, Key}, KeysToGet) of - KeysToGet -> % same list, key not found + KeysToGet -> % same list, key not found {LeafsFound, KeysToGet2} = get_key_leafs_simple(Pos + 1, SubTree, KeysToGet, [Key | KeyPathAcc]), {RestLeafsFound, KeysRemaining} = get_key_leafs_simple(Pos, RestTree, KeysToGet2, KeyPathAcc), {LeafsFound ++ RestLeafsFound, KeysRemaining}; @@ -201,10 +201,10 @@ get(Tree, KeysToGet) -> {KeyPaths, KeysNotFound} = get_full_key_paths(Tree, KeysToGet), FixedResults = [ {Value, {Pos, [Key0 || {Key0, _} <- Path]}} || {Pos, [{_Key, Value}|_]=Path} <- KeyPaths], {FixedResults, KeysNotFound}. - + get_full_key_paths(Tree, Keys) -> get_full_key_paths(Tree, Keys, []). - + get_full_key_paths(_, [], Acc) -> {Acc, []}; get_full_key_paths([], Keys, Acc) -> @@ -212,8 +212,8 @@ get_full_key_paths([], Keys, Acc) -> get_full_key_paths([{Pos, Tree}|Rest], Keys, Acc) -> {Gotten, RemainingKeys} = get_full_key_paths(Pos, [Tree], Keys, []), get_full_key_paths(Rest, RemainingKeys, Gotten ++ Acc). - - + + get_full_key_paths(_Pos, _Tree, [], _KeyPathAcc) -> {[], []}; get_full_key_paths(_Pos, [], KeysToGet, _KeyPathAcc) -> @@ -233,12 +233,12 @@ get_full_key_paths(Pos, [{KeyId, Value, SubTree} | RestTree], KeysToGet, KeyPath get_all_leafs_full(Tree) -> get_all_leafs_full(Tree, []). - + get_all_leafs_full([], Acc) -> Acc; get_all_leafs_full([{Pos, Tree} | Rest], Acc) -> get_all_leafs_full(Rest, get_all_leafs_full_simple(Pos, [Tree], []) ++ Acc). - + get_all_leafs_full_simple(_Pos, [], _KeyPathAcc) -> []; get_all_leafs_full_simple(Pos, [{KeyId, Value, []} | RestTree], KeyPathAcc) -> @@ -253,7 +253,7 @@ get_all_leafs([], Acc) -> Acc; get_all_leafs([{Pos, Tree}|Rest], Acc) -> get_all_leafs(Rest, get_all_leafs_simple(Pos, [Tree], []) ++ Acc). - + get_all_leafs_simple(_Pos, [], _KeyPathAcc) -> []; get_all_leafs_simple(Pos, [{KeyId, Value, []} | RestTree], KeyPathAcc) -> @@ -266,7 +266,7 @@ count_leafs([]) -> 0; count_leafs([{_Pos,Tree}|Rest]) -> count_leafs_simple([Tree]) + count_leafs(Rest). - + count_leafs_simple([]) -> 0; count_leafs_simple([{_Key, _Value, []} | RestTree]) -> @@ -274,7 +274,7 @@ count_leafs_simple([{_Key, _Value, []} | RestTree]) -> count_leafs_simple([{_Key, _Value, SubTree} | RestTree]) -> count_leafs_simple(SubTree) + count_leafs_simple(RestTree). - + map(_Fun, []) -> []; map(Fun, [{Pos, Tree}|Rest]) -> @@ -287,7 +287,7 @@ map_simple(Fun, Pos, [{Key, Value, SubTree} | RestTree]) -> Value2 = Fun({Pos, Key}, Value), [{Key, Value2, map_simple(Fun, Pos + 1, SubTree)} | map_simple(Fun, Pos, RestTree)]. - + map_leafs(_Fun, []) -> []; map_leafs(Fun, [{Pos, Tree}|Rest]) -> @@ -306,9 +306,9 @@ map_leafs_simple(Fun, Pos, [{Key, Value, SubTree} | RestTree]) -> stem(Trees, Limit) -> % flatten each branch in a tree into a tree path Paths = get_all_leafs_full(Trees), - + Paths2 = [{Pos, lists:sublist(Path, Limit)} || {Pos, Path} <- Paths], - + % convert paths back to trees lists:foldl( fun({PathPos, Path},TreeAcc) -> |