couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] 01/02: In couch_key_tree:stem/4 also update `Seen` set for a leaf child.
Date Tue, 16 Jan 2018 16:07:16 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch optimize-doc-updates
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 5f94c0a37d81317a320af1b0b8bcc300744c270b
Author: Nick Vatamaniuc <vatamane@apache.org>
AuthorDate: Mon Jan 15 17:24:45 2018 -0500

    In couch_key_tree:stem/4 also update `Seen` set for a leaf child.
    
    Moved set update to a separate function since it's common code.
---
 src/couch/src/couch_key_tree.erl | 18 ++++++++++++------
 1 file changed, 12 insertions(+), 6 deletions(-)

diff --git a/src/couch/src/couch_key_tree.erl b/src/couch/src/couch_key_tree.erl
index 24c48d2..c05ebe2 100644
--- a/src/couch/src/couch_key_tree.erl
+++ b/src/couch/src/couch_key_tree.erl
@@ -500,14 +500,11 @@ stem_tree({Depth, Child}, Limit, Seen) ->
     end.
 
 
-stem_tree(_Depth, {_Key, _Val, []} = Leaf, Limit, Seen) ->
-    {Seen, Limit - 1, Leaf, []};
+stem_tree(_Depth, {Key, _Val, []} = Leaf, Limit, Seen) ->
+    {check_key(Key, Seen), Limit - 1, Leaf, []};
 
 stem_tree(Depth, {Key, Val, Children}, Limit, Seen0) ->
-    Seen1 = case sets:is_element(Key, Seen0) of
-        true -> throw(dupe_keys);
-        false -> sets:add_element(Key, Seen0)
-    end,
+    Seen1 = check_key(Key, Seen0),
     FinalAcc = lists:foldl(fun(Child, Acc) ->
         {SeenAcc, LimitPosAcc, ChildAcc, BranchAcc} = Acc,
         case stem_tree(Depth + 1, Child, Limit, SeenAcc) of
@@ -537,6 +534,15 @@ stem_tree(Depth, {Key, Val, Children}, Limit, Seen0) ->
     end.
 
 
+check_key(Key, Seen) ->
+    case sets:is_element(Key, Seen) of
+        true ->
+            throw(dupe_keys);
+        false ->
+            sets:add_element(Key, Seen)
+    end.
+
+
 repair_tree(Trees, Limit) ->
     % flatten each branch in a tree into a tree path, sort by starting rev #
     Paths = lists:sort(lists:map(fun({Pos, Path}) ->

-- 
To stop receiving notification emails like this one, please contact
"commits@couchdb.apache.org" <commits@couchdb.apache.org>.

Mime
View raw message