-module(bravo@bag). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([new/3, insert/2, lookup/2, delete/1]). -export_type([bag/1]). -opaque bag(GDZ) :: {bag, gleam@erlang@atom:atom_(), integer()} | {gleam_phantom, GDZ}. -spec new(binary(), integer(), bravo@etc:access()) -> {ok, 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, [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, {bag, A, Keypos}} end ) end ). -spec insert(bag(GEF), list(GEF)) -> boolean(). insert(Bag, Objects) -> bravo:try_insert(erlang:element(2, Bag), erlang:element(3, Bag), Objects). -spec lookup(bag(GEI), any()) -> list(GEI). lookup(Bag, Key) -> bravo:try_lookup(erlang:element(2, Bag), Key). -spec delete(bag(any())) -> boolean(). delete(Bag) -> bravo:try_delete(erlang:element(2, Bag)).