Current section
Files
Jump to
Current section
Files
src/bravo@uset.erl
-module(bravo@uset).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/3, insert/2, lookup/2, delete/1]).
-export_type([u_set/1]).
-opaque u_set(GIV) :: {u_set, gleam@erlang@atom:atom_(), integer()} |
{gleam_phantom, GIV}.
-spec new(binary(), integer(), bravo@etc:access()) -> {ok, u_set(any())} |
{error, gleam@option:option(bravo@error:erlang_error())}.
new(Name, Keypos, Access) ->
Atom = erlang:binary_to_atom(Name),
gleam@bool:guard(
Keypos < 1,
{error, none},
fun() ->
gleam@result:'try'(
begin
_pipe = bravo:try_new(Atom, [set, case Access of
public ->
public;
protected ->
protected;
private ->
private
end, named_table, {keypos, Keypos}, {write_concurrency,
auto}, {read_concurrency, true}, {decentralized_counters,
true}]),
gleam@result:map_error(_pipe, fun(E) -> {some, E} end)
end,
fun(A) -> {ok, {u_set, A, Keypos}} end
)
end
).
-spec insert(u_set(GJB), list(GJB)) -> boolean().
insert(Uset, Objects) ->
bravo:try_insert(erlang:element(2, Uset), erlang:element(3, Uset), Objects).
-spec lookup(u_set(GJE), any()) -> gleam@option:option(GJE).
lookup(Uset, Key) ->
case bravo:try_lookup(erlang:element(2, Uset), Key) of
[Res] ->
{some, Res};
_ ->
none
end.
-spec delete(u_set(any())) -> boolean().
delete(Uset) ->
bravo:try_delete(erlang:element(2, Uset)).