Skip to content

Instantly share code, notes, and snippets.

@abhi-bit abhi-bit/merger.erl
Created Jan 6, 2016

Embed
What would you like to do?
-on_load(init/0).
-module(merger).
-on_load(init/0).
-export([
new/0, new/1, new/2,
out/1,
in/3,
size/1,
keys/1
]).
-define(NOT_LOADED,
erlang:nif_error({not_loaded, [{module, ?MODULE}, {line, ?LINE}]})).
init() ->
error_logger:error_msg("ABHI: ets fetch: ~p~n", [couch_config:get("couchdb", "merger_dir")]),
error_logger:error_msg("ABHI: util:priv_dir() ~p~n", [filename:join(couch_util:priv_dir(), "lib")]),
SoName = case couch_config:get("couchdb", "merger_dir") of
undefined ->
filename:join([couch_util:priv_dir(), "lib", "merger"]);
SoName0 ->
SoName0
end,
NumScheds = erlang:system_info(schedulers),
error_logger:error_msg("ABHI: SoName: ~p~n", [SoName]),
erlang:load_nif(SoName, NumScheds).
new() ->
new([], []).
new(KVs) ->
new(KVs, []).
new(KVs, Opts) ->
case new_nif(Opts) of
{ok, Heap} ->
lists:foreach(fun({K, V}) -> ?MODULE:put(Heap, K, V) end, KVs),
{ok, Heap};
Else ->
Else
end.
new_nif(_Options) ->
?NOT_LOADED.
out(_Heap) ->
?NOT_LOADED.
in(_Heap, _Key, _Val) ->
?NOT_LOADED.
size(_Heap) ->
?NOT_LOADED.
keys(_Heap) ->
?NOT_LOADED.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.