summaryrefslogtreecommitdiff
path: root/src/ts.erl
diff options
context:
space:
mode:
authorLinus Nordberg <linus@nordberg.se>2014-09-09 16:29:53 +0200
committerLinus Nordberg <linus@nordberg.se>2014-09-09 16:52:57 +0200
commitfbf64f31f34a12a9fc983f74bec27e5fbbe85f34 (patch)
tree74ba2a26673c4686f0baaad658918e1cf216bc59 /src/ts.erl
parente7a1ca43af470b6e99c0e11d845903f9bf00c723 (diff)
New hash tree implementation, using an ETS table for the hashes.
Also, add an untested entry storage implementation, using multiple DETS tables.
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).