You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2020/07/28 21:18:49 UTC
[couchdb] 01/01: Replace the 'true' clauses in visit with more
explicit ones
This is an automated email from the ASF dual-hosted git repository.
rnewson pushed a commit to branch prototype/fdb-layer-ebtree-true-clauses
in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 609505cc6b4540f2562e5ca1415f98b941ba73c9
Author: Robert Newson <rn...@apache.org>
AuthorDate: Tue Jul 28 22:18:08 2020 +0100
Replace the 'true' clauses in visit with more explicit ones
---
src/ebtree/src/ebtree.erl | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)
diff --git a/src/ebtree/src/ebtree.erl b/src/ebtree/src/ebtree.erl
index f08e1e9..84abab5 100644
--- a/src/ebtree/src/ebtree.erl
+++ b/src/ebtree/src/ebtree.erl
@@ -241,15 +241,16 @@ full_reduce(Db, #tree{} = Tree) ->
reduce(Db, #tree{} = Tree, StartKey, EndKey) ->
Fun = fun
({visit, Key, Value}, {MapAcc, ReduceAcc}) ->
+ BeforeStart = less_than(Tree, Key, StartKey),
AfterEnd = greater_than(Tree, Key, EndKey),
InRange = greater_than_or_equal(Tree, Key, StartKey) andalso less_than_or_equal(Tree, Key, EndKey),
if
+ BeforeStart ->
+ {ok, {MapAcc, ReduceAcc}}; %% ignore it.
AfterEnd ->
{stop, {MapAcc, ReduceAcc}};
InRange ->
- {ok, {[{Key, Value} | MapAcc], ReduceAcc}};
- true ->
- {ok, {MapAcc, ReduceAcc}}
+ {ok, {[{Key, Value} | MapAcc], ReduceAcc}}
end;
({traverse, FirstKey, LastKey, Reduction}, {MapAcc, ReduceAcc}) ->
BeforeStart = less_than(Tree, LastKey, StartKey),
@@ -322,6 +323,10 @@ group_reduce(Db, #tree{} = Tree, StartKey, EndKey, GroupKeyFun, UserAccFun, User
KeyGroup = GroupKeyFun(Key),
SameGroup = CurrentGroup =:= KeyGroup,
if
+ Dir == fwd andalso BeforeStart ->
+ {ok, {CurrentGroup, UserAcc, MapAcc, ReduceAcc}};
+ Dir == rev andalso AfterEnd ->
+ {ok, {CurrentGroup, UserAcc, MapAcc, ReduceAcc}};
Dir == fwd andalso AfterEnd ->
{stop, {CurrentGroup, UserAcc, MapAcc, ReduceAcc}};
Dir == rev andalso BeforeStart ->
@@ -333,9 +338,7 @@ group_reduce(Db, #tree{} = Tree, StartKey, EndKey, GroupKeyFun, UserAccFun, User
InRange ->
%% implicit end of current group and start of a new one
GroupValue = do_reduce(Tree, MapAcc, ReduceAcc),
- {ok, {KeyGroup, UserAccFun({CurrentGroup, GroupValue}, UserAcc), [{Key, Value}], []}};
- true ->
- {ok, {CurrentGroup, UserAcc, MapAcc, ReduceAcc}}
+ {ok, {KeyGroup, UserAccFun({CurrentGroup, GroupValue}, UserAcc), [{Key, Value}], []}}
end;
({traverse, FirstKey, LastKey, Reduction}, {CurrentGroup, UserAcc, MapAcc, ReduceAcc}) ->
BeforeStart = less_than(Tree, LastKey, StartKey),