summaryrefslogtreecommitdiff
path: root/src/ts.erl
diff options
context:
space:
mode:
Diffstat (limited to 'src/ts.erl')
-rw-r--r--src/ts.erl34
1 files changed, 34 insertions, 0 deletions
diff --git a/src/ts.erl b/src/ts.erl
new file mode 100644
index 0000000..8ea4895
--- /dev/null
+++ b/src/ts.erl
@@ -0,0 +1,34 @@
+% tree storage
+-module(ts).
+-include_lib("eunit/include/eunit.hrl").
+-export_type([tree_store/0]).
+-export([new/0, delete/1, store/3, retrieve/2, retrieve_hash/2]).
+
+%% -record(tree_store, {warm :: ets:tid(),
+%% frozen :: list()}). % [ets:tid()]
+-record(tree_store, {table :: ets:tid()}).
+-type tree_store() :: #tree_store{}.
+
+new() ->
+ %% tree_store#{warm = ets:new(nil, [{read_concurrency, true}]),
+ %% frozen = ets:new(nil, [{read_concurrency, true}])}.
+ #tree_store{table = ets:new(nil, [{read_concurrency, true}])}.
+
+delete(Store) ->
+ ets:delete(Store#tree_store.table).
+
+-spec store(tree_store(), tuple(), binary()) -> tree_store().
+store(Store, IR, Hash) ->
+ ets:insert(Store#tree_store.table, {IR, Hash}),
+ Store.
+
+-spec retrieve(tree_store(), tuple()) -> {tuple(), binary()}.
+retrieve(#tree_store{table = Tab}, IR) ->
+ case ets:lookup(Tab, IR) of
+ [] -> exit(IR);
+ [R] -> R
+ end.
+
+-spec retrieve_hash(tree_store(), tuple()) -> binary().
+retrieve_hash(#tree_store{table = Tab}, IR) ->
+ ets:lookup_element(Tab, IR, 2).