diff options
author | Robert Newson <robert.newson@cloudant.com> | 2011-09-28 11:18:06 +0100 |
---|---|---|
committer | Robert Newson <robert.newson@cloudant.com> | 2011-09-28 11:32:50 +0100 |
commit | 954ddf0fca558f17f39e68df8311ee9057beb390 (patch) | |
tree | 2542c112210363076be1a8bc7b24e13bfaf1c055 /apps/couch/src/couch_key_tree.erl | |
parent | c8d7b6d8c3cb881d525be80bc6b16bc08822df65 (diff) | |
parent | befbdfb11f45bd2a5ccffb6b0d5ac04435ac9e55 (diff) |
Merge 1.1.x changes
Conflicts:
apps/couch/include/couch_db.hrl
apps/couch/src/couch_db.erl
apps/couch/src/couch_os_process.erl
apps/couch/src/couch_query_servers.erl
apps/couch/src/couch_rep.erl
apps/couch/src/couch_replication_manager.erl
apps/couch/src/couch_view_compactor.erl
apps/couch/src/couch_view_group.erl
apps/couch/src/couch_view_updater.erl
configure.ac
couchjs/c_src/http.c
couchjs/c_src/main.c
couchjs/c_src/utf8.c
etc/windows/couchdb.iss.tpl
src/couchdb/priv/Makefile.am
src/couchdb/priv/couch_js/main.c
test/etap/160-vhosts.t
test/etap/200-view-group-no-db-leaks.t
test/etap/Makefile.am
BugzID: 12645
Diffstat (limited to 'apps/couch/src/couch_key_tree.erl')
-rw-r--r-- | apps/couch/src/couch_key_tree.erl | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/apps/couch/src/couch_key_tree.erl b/apps/couch/src/couch_key_tree.erl index 2f3c6abf..5e24e0f7 100644 --- a/apps/couch/src/couch_key_tree.erl +++ b/apps/couch/src/couch_key_tree.erl @@ -50,7 +50,7 @@ -export([merge/3, find_missing/2, get_key_leafs/2, get_full_key_paths/2, get/2, compute_data_size/1]). -export([map/2, get_all_leafs/1, count_leafs/1, remove_leafs/2, - get_all_leafs_full/1,stem/2,map_leafs/2]). + get_all_leafs_full/1,stem/2,map_leafs/2, fold/3]). -include("couch_db.hrl"). @@ -373,6 +373,21 @@ tree_fold_simple(Fun, Pos, [{Key, Value, SubTree} | RestTree], Acc) -> Acc2 end. +fold(_Fun, Acc, []) -> + Acc; +fold(Fun, Acc0, [{Pos, Tree}|Rest]) -> + Acc1 = fold_simple(Fun, Acc0, Pos, [Tree]), + fold(Fun, Acc1, Rest). + +fold_simple(_Fun, Acc, _Pos, []) -> + Acc; +fold_simple(Fun, Acc0, Pos, [{Key, Value, SubTree} | RestTree]) -> + Type = if SubTree == [] -> leaf; true -> branch end, + Acc1 = Fun({Pos, Key}, Value, Type, Acc0), + Acc2 = fold_simple(Fun, Acc1, Pos+1, SubTree), + fold_simple(Fun, Acc2, Pos, RestTree). + + map(_Fun, []) -> []; map(Fun, [{Pos, Tree}|Rest]) -> |