% 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).