-module(carpenter@builder). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new/1, privacy/2, write_concurrency/2, read_concurrency/2, decentralized_counters/2, compression/2, write_concurrency_prop/1, build_table/2, set/1, ordered_set/1]). -export_type([table_builder/2]). -type table_builder(GCT, GCU) :: {table_builder, binary(), gleam@option:option(carpenter@config@privacy:privacy()), gleam@option:option(carpenter@config@write_concurrency:write_concurrency()), gleam@option:option(boolean()), gleam@option:option(boolean()), boolean()} | {gleam_phantom, GCT, GCU}. -spec new(binary()) -> table_builder(any(), any()). new(Name) -> {table_builder, Name, none, none, none, none, false}. -spec privacy(table_builder(GDA, GDB), carpenter@config@privacy:privacy()) -> table_builder(GDA, GDB). privacy(Builder, Privacy) -> erlang:setelement(3, Builder, {some, Privacy}). -spec write_concurrency( table_builder(GDG, GDH), carpenter@config@write_concurrency:write_concurrency() ) -> table_builder(GDG, GDH). write_concurrency(Builder, Con) -> erlang:setelement(4, Builder, {some, Con}). -spec read_concurrency(table_builder(GDM, GDN), boolean()) -> table_builder(GDM, GDN). read_concurrency(Builder, Con) -> erlang:setelement(5, Builder, {some, Con}). -spec decentralized_counters(table_builder(GDS, GDT), boolean()) -> table_builder(GDS, GDT). decentralized_counters(Builder, Counters) -> erlang:setelement(6, Builder, {some, Counters}). -spec compression(table_builder(GDY, GDZ), boolean()) -> table_builder(GDY, GDZ). compression(Builder, Compressed) -> erlang:setelement(7, Builder, Compressed). -spec privacy_prop(carpenter@config@privacy:privacy()) -> gleam@dynamic:dynamic_(). privacy_prop(Prop) -> _pipe = case Prop of private -> <<"private"/utf8>>; protected -> <<"protected"/utf8>>; public -> <<"public"/utf8>> end, _pipe@1 = erlang:binary_to_atom(_pipe), gleam@dynamic:from(_pipe@1). -spec write_concurrency_prop( carpenter@config@write_concurrency:write_concurrency() ) -> gleam@dynamic:dynamic_(). write_concurrency_prop(Prop) -> _pipe = case Prop of true -> <<"true"/utf8>>; false -> <<"false"/utf8>>; auto -> <<"auto"/utf8>> end, _pipe@1 = erlang:binary_to_atom(_pipe), _pipe@2 = (fun(X) -> {erlang:binary_to_atom(<<"write_concurrency"/utf8>>), X} end)(_pipe@1), gleam@dynamic:from(_pipe@2). -spec build_table(table_builder(any(), any()), binary()) -> gleam@erlang@atom:atom_(). build_table(Builder, Table_type) -> Name = erlang:binary_to_atom(erlang:element(2, Builder)), Props = begin _pipe = [erlang:binary_to_atom(Table_type), erlang:binary_to_atom(<<"named_table"/utf8>>)], gleam@list:map(_pipe, fun gleam@dynamic:from/1) end, Props@1 = case erlang:element(3, Builder) of {some, X} -> [privacy_prop(X) | Props]; _ -> Props end, Props@2 = case erlang:element(4, Builder) of {some, X@1} -> [write_concurrency_prop(X@1) | Props@1]; _ -> Props@1 end, Props@3 = case erlang:element(5, Builder) of {some, X@2} -> [begin _pipe@1 = {erlang:binary_to_atom( <<"read_concurrency"/utf8>> ), X@2}, gleam@dynamic:from(_pipe@1) end | Props@2]; _ -> Props@2 end, Props@4 = case erlang:element(7, Builder) of true -> [begin _pipe@2 = erlang:binary_to_atom(<<"compressed"/utf8>>), gleam@dynamic:from(_pipe@2) end | Props@3]; false -> Props@3 end, ets:new( Name, begin _pipe@3 = Props@4, gleam@list:map(_pipe@3, fun gleam@dynamic:from/1) end ), Name. -spec set(table_builder(GEI, GEJ)) -> carpenter@internal@table_type@set:set(GEI, GEJ). set(Builder) -> Table = build_table(Builder, <<"set"/utf8>>), {set, carpenter@table:new(Table)}. -spec ordered_set(table_builder(GEO, GEP)) -> carpenter@internal@table_type@ordered_set:ordered_set(GEO, GEP). ordered_set(Builder) -> Table = build_table(Builder, <<"ordered_set"/utf8>>), {ordered_set, carpenter@table:new(Table)}.