Created
June 30, 2009 14:49
-
-
Save mallipeddi/138194 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(mattress). | |
-author("Harish Mallipeddi <harish.mallipeddi@gmail.com>"). | |
-export([run_with/1]). | |
-export([behaviour_info/1]). | |
-record(btree, | |
{fd, | |
root, | |
extract_kv, | |
assemble_kv, | |
less, | |
reduce | |
}). | |
behaviour_info(callbacks) -> | |
[{map, 0}, {reduce, 2}]; | |
behaviour_info(_Other) -> | |
undefined. | |
run_with(Mod) -> | |
{ok, Fd} = couch_file:open("tweetbed.db", [create, overwrite]), | |
{ok, Bt1} = couch_btree:open(nil, Fd), | |
Bt2 = couch_btree:set_options(Bt1, [{reduce, {Mod, reduce}}]), | |
{ok, Bt3} = couch_btree:add(Bt2, erlang:apply(Mod, map, [])). | |
%% lookup some docs by keys | |
Results = couch_btree:lookup(Bt3, ["vyom", "jackerhack"]), | |
io:format("lookup out: ~p~n", [Results]), | |
%% get the top-level reduce value | |
io:format("fullreduce out: ~p~n", [couch_btree:full_reduce(Bt3)]), | |
couch_file:close(Fd). |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment