-module(bravo@dbag). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new/3, insert/2, lookup/2, delete/1]). -export_type([d_bag/1]). -opaque d_bag(GFO) :: {d_bag, gleam@erlang@atom:atom_(), integer()} | {gleam_phantom, GFO}. -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(GFU), list(GFU)) -> boolean(). insert(Dbag, Objects) -> bravo:try_insert(erlang:element(2, Dbag), erlang:element(3, Dbag), Objects). -spec lookup(d_bag(GFX), any()) -> list(GFX). 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)).