Current section
Files
Jump to
Current section
Files
src/reki@ets.erl
-module(reki@ets).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/reki/ets.gleam").
-export([new_table_identifier/0, new/1, insert/3, lookup/2, delete/2]).
-export_type([table_identifier/2, tid/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type table_identifier(FLV, FLW) :: any() | {gleam_phantom, FLV, FLW}.
-type tid() :: any().
-file("src/reki/ets.gleam", 37).
?DOC(
" Creates a unique atom for use as an ETS table name.\n"
" WARNING: Atoms are never garbage collected by the BEAM. Only call this\n"
" a fixed number of times (e.g. once per registry at app startup).\n"
).
-spec new_table_identifier() -> table_identifier(any(), any()).
new_table_identifier() ->
reki_ets_ffi:new_unique_atom().
-file("src/reki/ets.gleam", 42).
?DOC(
" Creates a new named ETS table. Crashes if the name is already taken.\n"
" The table is owned by the calling process and will be destroyed when it dies.\n"
).
-spec new(table_identifier(any(), any())) -> tid().
new(Table_id) ->
reki_ets_ffi:new(Table_id).
-file("src/reki/ets.gleam", 10).
?DOC(" Insert a key-value pair into the table.\n").
-spec insert(table_identifier(FLX, FLY), FLX, FLY) -> {ok, nil} | {error, nil}.
insert(Table_id, Key, Value) ->
reki_ets_ffi:insert(Table_id, Key, Value).
-file("src/reki/ets.gleam", 19).
?DOC(" Look up a value by key in the table.\n").
-spec lookup(table_identifier(FMD, FME), FMD) -> gleam@option:option(FME).
lookup(Table_id, Key) ->
reki_ets_ffi:lookup(Table_id, Key).
-file("src/reki/ets.gleam", 24).
?DOC(" Delete a key-value pair from the table.\n").
-spec delete(table_identifier(FMI, any()), FMI) -> {ok, nil} | {error, nil}.
delete(Table_id, Key) ->
reki_ets_ffi:delete(Table_id, Key).