Created
January 6, 2016 05:51
-
-
Save abhi-bit/3aea4ff78ffb52820260 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
-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