Current section
Files
Jump to
Current section
Files
src/bravo@dbag.erl
-module(bravo@dbag).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([new/3, insert/2, lookup/2, delete/1, delete_key/2, delete_all_objects/1, delete_object/2]).
-export_type([d_bag/1]).
-opaque d_bag(GGF) :: {d_bag, gleam@erlang@atom:atom_(), integer()} |
{gleam_phantom, GGF}.
-spec new(binary(), integer(), bravo@etc:access()) -> {ok, d_bag(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, [duplicate_bag, 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, {d_bag, A, Keypos}} end
)
end
).
-spec insert(d_bag(GGL), list(GGL)) -> boolean().
insert(Dbag, Objects) ->
bravo:try_insert(erlang:element(2, Dbag), erlang:element(3, Dbag), Objects).
-spec lookup(d_bag(GGO), any()) -> list(GGO).
lookup(Dbag, Key) ->
bravo:try_lookup(erlang:element(2, Dbag), Key).
-spec delete(d_bag(any())) -> boolean().
delete(Dbag) ->
bravo:try_delete(erlang:element(2, Dbag)).
-spec delete_key(d_bag(any()), any()) -> nil.
delete_key(Dbag, Key) ->
bravo:try_delete_key(erlang:element(2, Dbag), Key),
nil.
-spec delete_all_objects(d_bag(any())) -> nil.
delete_all_objects(Dbag) ->
bravo:try_delete_all_objects(erlang:element(2, Dbag)),
nil.
-spec delete_object(d_bag(GGZ), GGZ) -> nil.
delete_object(Dbag, Object) ->
bravo:try_delete_object(erlang:element(2, Dbag), Object),
nil.