Skip to content

Instantly share code, notes, and snippets.

@mallipeddi
Created June 30, 2009 14:49
Show Gist options
  • Save mallipeddi/138194 to your computer and use it in GitHub Desktop.
Save mallipeddi/138194 to your computer and use it in GitHub Desktop.
-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