View Source ETS.Set (ets v0.9.0)
Module for creating and interacting with :ets tables of the type :set
and :ordered_set
.
Sets contain "records" which are tuples. Sets are configured with a key position via the keypos: integer
option.
If not specified, the default key position is 1. The element of the tuple record at the key position is that records key.
For example, setting the keypos
to 2 means the key of an inserted record {:a, :b}
is :b
:
iex> {:ok, set} = Set.new(keypos: 2)
iex> Set.put!(set, {:a, :b})
iex> Set.get(set, :a)
{:ok, nil}
iex> Set.get(set, :b)
{:ok, {:a, :b}}
When a record is added to the table with put
, it will overwrite an existing record
with the same key. put_new
will only put the record if a matching key doesn't already exist.
examples
Examples
iex> {:ok, set} = Set.new(ordered: true)
iex> Set.put_new!(set, {:a, :b, :c})
iex> Set.to_list!(set)
[{:a, :b, :c}]
iex> Set.put_new!(set, {:d, :e, :f})
iex> Set.to_list!(set)
[{:a, :b, :c}, {:d, :e, :f}]
iex> Set.put_new!(set, {:a, :g, :h})
iex> Set.to_list!(set)
[{:a, :b, :c}, {:d, :e, :f}]
put
and put_new
take either a single tuple or a list of tuples. When inserting multiple records,
they are inserted in an atomic an isolated manner. put_new
doesn't insert any records if any of
the new keys already exist in the set.
To make your set ordered (which maps to the :ets
table type :ordered_set
), specify ordered: true
in the options list. An ordered set will store records in term order of the key of the record. This is
helpful when using things like first
, last
, previous
, next
, and to_list
, but comes with the penalty of
log(n) insert time vs consistent insert time of an unordered set.
working-with-named-tables
Working with named tables
The functions on ETS.Set
require that you pass in an ETS.Set
as the first argument. In some design patterns,
you may have the table name but an instance of an ETS.Set
may not be available to you. If this is the case,
you should use wrap_existing/1
to turn your table name atom into an ETS.Set
. For example, a GenServer
that
handles writes within the server, but reads in the client process would be implemented like this:
defmodule MyExampleGenServer do
use GenServer
# Client Functions
def get_token_for_user(user_id) do
:my_token_table
|> ETS.Set.wrap_existing!()
|> ETS.Set.get!(user_id)
|> elem(1)
end
def set_token_for_user(user_id, token) do
GenServer.call(__MODULE__, {:set_token_for_user, user_id, token})
end
# Server Functions
def init(_) do
{:ok, %{set: ETS.Set.new!(name: :my_token_table)}}
end
def handle_call({:set_token_for_user, user_id, token}, _from, %{set: set}) do
ETS.Set.put(set, user_id, token)
end
end
Link to this section Summary
Functions
Waits to accept ownership of a table after it is given away. Successful receipt will
return {:ok, %{set: set, from: from, gift: gift}}
where from
is the pid of the previous
owner, and gift
is any additional metadata sent with the table.
For processes which may receive ownership of a Set unexpectedly - either via give_away/3
or
by being named the Set's heir (see new/1
) - the module should include at least one accept
clause. For example, if we want a server to inherit Sets after their previous owner dies
Deletes specified Set.
Deletes record with specified key in specified Set.
Same as delete/1
but unwraps or raises on error.
Same as delete/2
but unwraps or raises on error.
Deletes all records in specified Set.
Same as delete_all/1
but unwraps or raises on error.
Returns record with specified key or an error if no record found.
Returns the first key in the specified Set. Set must be ordered or error is returned.
Same as first/1
but unwraps or raises on error
Returns record with specified key or the provided default (nil if not specified) if no record found.
Same as get/3
but unwraps or raises on error.
Returns element in specified position of record with specified key.
Same as get_element/3
but unwraps or raises on error.
Returns underlying :ets
table reference.
Same as get_table/1
but unwraps or raises on error
Transfers ownership of a Set to another process.
Same as give_away/3
but unwraps or raises on error.
Determines if specified key exists in specified set.
Same as has_key/2
but unwraps or raises on error.
Returns information on the set.
Same as info/1
but unwraps or raises on error.
Returns the last key in the specified Set. Set must be ordered or error is returned.
Same as last/1
but unwraps or raises on error
Matches next set of records from a match/3 or match/1 continuation.
Returns records in the specified Set that match the specified pattern.
Same as match/2
but limits number of results to the specified limit.
Same as match/1
but unwraps or raises on error.
Same as match/2
but unwraps or raises on error.
Same as match/3
but unwraps or raises on error.
Deletes all records that match the specified pattern.
Same as match_delete/2
but unwraps or raises on error.
Matches next records from a match_object/3 or match_object/1 continuation.
Returns records in the specified Set that match the specified pattern.
Same as match_object/2
but limits number of results to the specified limit.
Same as match_object/1
but unwraps or raises on error.
Same as match_object/2
but unwraps or raises on error.
Same as match_object/3
but unwraps or raises on error.
Creates new set module with the specified options.
Same as new/1
but unwraps or raises on error.
Returns the next key in the specified Set.
Same as next/1
but unwraps or raises on error
Returns the previous key in the specified Set.
Same as previous/1
but raises on :error
Puts tuple record or list of tuple records into table. Overwrites records for existing key(s).
Same as put/2
but unwraps or raises on error.
Same as put/2
but doesn't put any records if one of the given keys already exists.
Same as put_new/2
but unwraps or raises on error.
Returns records in the specified Set that match the specified match specification.
Same as select/2
but limits the number of results returned.
Same as select/2
but unwraps or raises on error.
Same as select/3
but unwraps or raises on error.
Deletes records in the specified Set that match the specified match specification.
Same as select_delete/2
but unwraps or raises on error.
Returns contents of table as a list.
Same as to_list/1
but unwraps or raises on error.
Updates one or more elements within the record with the given key
. The element_spec is
a tuple (or list of tuples) of the form {position, value}
, which will update the element
at position
(1-indexed) to have the given value
. When a list is given, multiple elements
can be updated within the same record. If the same position occurs more than once in the list,
the last value in the list is written. If the list is empty or the function fails, no updates
are done. The function is also atomic in the sense that other processes can never see any
intermediate results.
Same as update_element/3
but unwraps or raises on error.
Wraps an existing :ets :set or :ordered_set in a Set struct.
Same as wrap_existing/1
but unwraps or raises on error.
Link to this section Types
Specs
set_options() :: [ETS.Base.option() | {:ordered, boolean()}]
Specs
t() :: %ETS.Set{ info: keyword(), ordered: boolean(), table: ETS.table_reference() }
Link to this section Functions
Waits to accept ownership of a table after it is given away. Successful receipt will
return {:ok, %{set: set, from: from, gift: gift}}
where from
is the pid of the previous
owner, and gift
is any additional metadata sent with the table.
A timeout may be given in milliseconds, which will return {:error, :timeout}
if reached.
See give_away/3
for more information.
For processes which may receive ownership of a Set unexpectedly - either via give_away/3
or
by being named the Set's heir (see new/1
) - the module should include at least one accept
clause. For example, if we want a server to inherit Sets after their previous owner dies:
defmodule Receiver do
use GenServer
alias ETS.Set
require ETS.Set
...
Set.accept :owner_crashed, set, _from, state do
new_state = Map.update!(state, :crashed_sets, &[set | &1])
{:noreply, new_state}
end
The first argument is a unique identifier which should match either the "heir_data"
in new/1
, or the "gift" in give_away/3
.
The other arguments declare the variables which may be used in the do
block:
the received Set, the pid of the previous owner, and the current state of the process.
The return value should be in the form {:noreply, new_state}, or one of the similar
returns expected by handle_info
/handle_cast
.
Specs
Deletes specified Set.
examples
Examples
iex> {:ok, set} = Set.new()
iex> {:ok, _} = Set.info(set, true)
iex> {:ok, _} = Set.delete(set)
iex> Set.info(set, true)
{:error, :table_not_found}
Specs
Deletes record with specified key in specified Set.
examples
Examples
iex> set = Set.new!()
iex> Set.put(set, {:a, :b, :c})
iex> Set.delete(set, :a)
iex> Set.get!(set, :a)
nil
Specs
Same as delete/1
but unwraps or raises on error.
Specs
Same as delete/2
but unwraps or raises on error.
Specs
Deletes all records in specified Set.
examples
Examples
iex> set = Set.new!()
iex> set
iex> |> Set.put!({:a, :b, :c})
iex> |> Set.put!({:b, :b, :c})
iex> |> Set.put!({:c, :b, :c})
iex> |> Set.to_list!()
[{:c, :b, :c}, {:b, :b, :c}, {:a, :b, :c}]
iex> Set.delete_all(set)
iex> Set.to_list!(set)
[]
Specs
Same as delete_all/1
but unwraps or raises on error.
Specs
Returns record with specified key or an error if no record found.
examples
Examples
iex> Set.new!()
iex> |> Set.put!({:a, :b, :c})
iex> |> Set.put!({:d, :e, :f})
iex> |> Set.fetch(:d)
{:ok, {:d, :e, :f}}
iex> Set.new!()
iex> |> Set.put!({:a, :b, :c})
iex> |> Set.put!({:d, :e, :f})
iex> |> Set.fetch(:g)
{:error, :key_not_found}
Specs
Returns the first key in the specified Set. Set must be ordered or error is returned.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.first(set)
{:error, :empty_table}
iex> Set.put!(set, {:key1, :val})
iex> Set.put!(set, {:key2, :val})
iex> Set.first(set)
{:ok, :key1}
Specs
Same as first/1
but unwraps or raises on error
Specs
Returns record with specified key or the provided default (nil if not specified) if no record found.
examples
Examples
iex> Set.new!()
iex> |> Set.put!({:a, :b, :c})
iex> |> Set.put!({:d, :e, :f})
iex> |> Set.get(:d)
{:ok, {:d, :e, :f}}
Specs
Same as get/3
but unwraps or raises on error.
Specs
get_element(t(), any(), non_neg_integer()) :: {:ok, any()} | {:error, any()}
Returns element in specified position of record with specified key.
examples
Examples
iex> Set.new!()
iex> |> Set.put!({:a, :b, :c})
iex> |> Set.put!({:d, :e, :f})
iex> |> Set.get_element(:d, 2)
{:ok, :e}
Specs
get_element!(t(), any(), non_neg_integer()) :: any()
Same as get_element/3
but unwraps or raises on error.
Specs
get_table(t()) :: {:ok, ETS.table_reference()}
Returns underlying :ets
table reference.
For use in functions that are not yet implemented. If you find yourself using this, please consider
submitting a PR to add the necessary function to ETS
.
examples
Examples
iex> set = Set.new!(name: :my_ets_table)
iex> {:ok, table} = Set.get_table(set)
iex> info = :ets.info(table)
iex> info[:name]
:my_ets_table
Specs
get_table!(t()) :: ETS.table_reference()
Same as get_table/1
but unwraps or raises on error
Specs
Transfers ownership of a Set to another process.
examples
Examples
iex> set = Set.new!()
iex> receiver_pid = spawn(fn -> Set.accept() end)
iex> Set.give_away(set, receiver_pid)
{:ok, set}
iex> set = Set.new!()
iex> dead_pid = ETS.TestUtils.dead_pid()
iex> Set.give_away(set, dead_pid)
{:error, :recipient_not_alive}
Specs
Same as give_away/3
but unwraps or raises on error.
Specs
Determines if specified key exists in specified set.
examples
Examples
iex> set = Set.new!()
iex> Set.has_key(set, :key)
{:ok, false}
iex> Set.put(set, {:key, :value})
iex> Set.has_key(set, :key)
{:ok, true}
Specs
Same as has_key/2
but unwraps or raises on error.
Specs
Returns information on the set.
Second parameter forces updated information from ets, default (false) uses in-struct cached information. Force should be used when requesting size and memory.
examples
Examples
iex> {:ok, set} = Set.new(ordered: true, keypos: 3, read_concurrency: true, compressed: false)
iex> {:ok, info} = Set.info(set)
iex> info[:read_concurrency]
true
iex> {:ok, _} = Set.put(set, {:a, :b, :c})
iex> {:ok, info} = Set.info(set)
iex> info[:size]
0
iex> {:ok, info} = Set.info(set, true)
iex> info[:size]
1
Specs
Same as info/1
but unwraps or raises on error.
Specs
Returns the last key in the specified Set. Set must be ordered or error is returned.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.last(set)
{:error, :empty_table}
iex> Set.put!(set, {:key1, :val})
iex> Set.put!(set, {:key2, :val})
iex> Set.last(set)
{:ok, :key2}
Specs
Same as last/1
but unwraps or raises on error
Specs
Matches next set of records from a match/3 or match/1 continuation.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, [{:a, :b, :c, :d}, {:e, :b, :f, :g}, {:h, :b, :i, :j}])
iex> {:ok, {results, continuation}} = Set.match(set, {:"$1", :b, :"$2", :_}, 2)
iex> results
[[:a, :c], [:e, :f]]
iex> {:ok, {records2, continuation2}} = Set.match(continuation)
iex> records2
[[:h, :i]]
iex> continuation2
:end_of_table
Specs
match(t(), ETS.match_pattern()) :: {:ok, [tuple()]} | {:error, any()}
Returns records in the specified Set that match the specified pattern.
For more information on the match pattern, see the erlang documentation
examples
Examples
iex> Set.new!(ordered: true)
iex> |> Set.put!([{:a, :b, :c, :d}, {:e, :c, :f, :g}, {:h, :b, :i, :j}])
iex> |> Set.match({:"$1", :b, :"$2", :_})
{:ok, [[:a, :c], [:h, :i]]}
Specs
match(t(), ETS.match_pattern(), non_neg_integer()) :: {:ok, {[tuple()], any() | :end_of_table}} | {:error, any()}
Same as match/2
but limits number of results to the specified limit.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, [{:a, :b, :c, :d}, {:e, :b, :f, :g}, {:h, :b, :i, :j}])
iex> {:ok, {results, _continuation}} = Set.match(set, {:"$1", :b, :"$2", :_}, 2)
iex> results
[[:a, :c], [:e, :f]]
Specs
Same as match/1
but unwraps or raises on error.
Specs
match!(t(), ETS.match_pattern()) :: [tuple()]
Same as match/2
but unwraps or raises on error.
Specs
match!(t(), ETS.match_pattern(), non_neg_integer()) :: {[tuple()], any() | :end_of_table}
Same as match/3
but unwraps or raises on error.
Specs
match_delete(t(), ETS.match_pattern()) :: {:ok, t()} | {:error, any()}
Deletes all records that match the specified pattern.
Always returns :ok
, regardless of whether anything was deleted or not.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, [{:a, :b, :c, :d}, {:e, :b, :f, :g}, {:h, :i, :j, :k}])
iex> Set.match_delete(set, {:_, :b, :_, :_})
{:ok, set}
iex> Set.to_list!(set)
[{:h, :i, :j, :k}]
Specs
match_delete!(t(), ETS.match_pattern()) :: t()
Same as match_delete/2
but unwraps or raises on error.
Specs
Matches next records from a match_object/3 or match_object/1 continuation.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, [{:a, :b, :c}, {:d, :b, :e}, {:f, :b, :g}, {:h, :b, :i}])
iex> {:ok, {results, continuation}} = Set.match_object(set, {:"$1", :b, :_}, 2)
iex> results
[{:a, :b, :c}, {:d, :b, :e}]
iex> {:ok, {results2, continuation2}} = Set.match_object(continuation)
iex> results2
[{:f, :b, :g}, {:h, :b, :i}]
iex> {:ok, {[], :end_of_table}} = Set.match_object(continuation2)
Specs
match_object(t(), ETS.match_pattern()) :: {:ok, [tuple()]} | {:error, any()}
Returns records in the specified Set that match the specified pattern.
For more information on the match pattern, see the erlang documentation
examples
Examples
iex> Set.new!(ordered: true)
iex> |> Set.put!([{:a, :b, :c, :d}, {:e, :c, :f, :g}, {:h, :b, :i, :j}])
iex> |> Set.match_object({:"$1", :b, :"$2", :_})
{:ok, [{:a, :b, :c, :d}, {:h, :b, :i, :j}]}
Specs
match_object(t(), ETS.match_pattern(), non_neg_integer()) :: {:ok, {[tuple()], any() | :end_of_table}} | {:error, any()}
Same as match_object/2
but limits number of results to the specified limit.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, [{:a, :b, :c, :d}, {:e, :b, :f, :g}, {:h, :b, :i, :j}])
iex> {:ok, {results, _continuation}} = Set.match_object(set, {:"$1", :b, :"$2", :_}, 2)
iex> results
[{:a, :b, :c, :d}, {:e, :b, :f, :g}]
Specs
Same as match_object/1
but unwraps or raises on error.
Specs
match_object!(t(), ETS.match_pattern()) :: [tuple()]
Same as match_object/2
but unwraps or raises on error.
Specs
match_object!(t(), ETS.match_pattern(), non_neg_integer()) :: {[tuple()], any() | :end_of_table}
Same as match_object/3
but unwraps or raises on error.
Specs
new(set_options()) :: {:error, any()} | {:ok, t()}
Creates new set module with the specified options.
Note that the underlying :ets table will be attached to the process that calls new
and will be destroyed
if that process dies.
Possible options:
name:
when specified, creates a named table with the specified nameordered:
when true, records in set are ordered (default false)protection:
:private, :protected, :public (default :protected)heir:
:none | {heir_pid, heir_data} (default :none)keypos:
integer (default 1)read_concurrency:
boolean (default false)write_concurrency:
boolean (default false)compressed:
boolean (default false)
examples
Examples
iex> {:ok, set} = Set.new(ordered: true, keypos: 3, read_concurrency: true, compressed: false)
iex> Set.info!(set)[:read_concurrency]
true
# Named :ets tables via the name keyword
iex> {:ok, set} = Set.new(name: :my_ets_table)
iex> Set.info!(set)[:name]
:my_ets_table
Specs
new!(set_options()) :: t()
Same as new/1
but unwraps or raises on error.
Specs
Returns the next key in the specified Set.
The given key does not need to exist in the set. The key returned will be the first key that exists in the set which is subsequent in term order to the key given.
Set must be ordered or error is returned.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, {:key1, :val})
iex> Set.put!(set, {:key2, :val})
iex> Set.put!(set, {:key3, :val})
iex> Set.first(set)
{:ok, :key1}
iex> Set.next(set, :key1)
{:ok, :key2}
iex> Set.next(set, :key2)
{:ok, :key3}
iex> Set.next(set, :key3)
{:error, :end_of_table}
iex> Set.next(set, :a)
{:ok, :key1}
iex> Set.next(set, :z)
{:error, :end_of_table}
Specs
Same as next/1
but unwraps or raises on error
Specs
Returns the previous key in the specified Set.
The given key does not need to exist in the set. The key returned will be the first key that exists in the set which is previous in term order to the key given.
Set must be ordered or error is returned.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> Set.put!(set, {:key1, :val})
iex> Set.put!(set, {:key2, :val})
iex> Set.put!(set, {:key3, :val})
iex> Set.last(set)
{:ok, :key3}
iex> Set.previous(set, :key3)
{:ok, :key2}
iex> Set.previous(set, :key2)
{:ok, :key1}
iex> Set.previous(set, :key1)
{:error, :start_of_table}
iex> Set.previous(set, :a)
{:error, :start_of_table}
iex> Set.previous(set, :z)
{:ok, :key3}
Specs
Same as previous/1
but raises on :error
Returns previous key in table.
Specs
Puts tuple record or list of tuple records into table. Overwrites records for existing key(s).
Inserts multiple records in an atomic and isolated manner.
examples
Examples
iex> {:ok, set} = Set.new(ordered: true)
iex> {:ok, _} = Set.put(set, [{:a, :b, :c}, {:d, :e, :f}])
iex> {:ok, _} = Set.put(set, {:g, :h, :i})
iex> {:ok, _} = Set.put(set, {:d, :x, :y})
iex> Set.to_list(set)
{:ok, [{:a, :b, :c}, {:d, :x, :y}, {:g, :h, :i}]}
Specs
Same as put/2
but unwraps or raises on error.
Specs
Same as put/2
but doesn't put any records if one of the given keys already exists.
examples
Examples
iex> set = Set.new!(ordered: true)
iex> {:ok, _} = Set.put_new(set, [{:a, :b, :c}, {:d, :e, :f}])
iex> {:ok, _} = Set.put_new(set, [{:a, :x, :y}, {:g, :h, :i}]) # skips due to duplicate :a key
iex> {:ok, _} = Set.put_new(set, {:d, :z, :zz}) # skips due to duplicate :d key
iex> Set.to_list!(set)
[{:a, :b, :c}, {:d, :e, :f}]
Specs
Same as put_new/2
but unwraps or raises on error.
Specs
select(ETS.continuation()) :: {:ok, {[tuple()], ETS.continuation()} | ETS.end_of_table()} | {:error, any()}
Specs
select(t(), ETS.match_spec()) :: {:ok, [tuple()]} | {:error, any()}
Returns records in the specified Set that match the specified match specification.
For more information on the match specification, see the erlang documentation
examples
Examples
iex> Set.new!(ordered: true)
iex> |> Set.put!([{:a, :b, :c, :d}, {:e, :c, :f, :g}, {:h, :b, :i, :j}])
iex> |> Set.select([{{:"$1", :b, :"$2", :_},[],[:"$$"]}])
{:ok, [[:a, :c], [:h, :i]]}
Specs
select(t(), ETS.match_spec(), limit :: integer()) :: {:ok, {[tuple()], ETS.continuation()} | ETS.end_of_table()} | {:error, any()}
Same as select/2
but limits the number of results returned.
Specs
select!(ETS.continuation()) :: {[tuple()], ETS.continuation()} | ETS.end_of_table()
Specs
select!(t(), ETS.match_spec()) :: [tuple()]
Same as select/2
but unwraps or raises on error.
Specs
select!(t(), ETS.match_spec(), limit :: integer()) :: {[tuple()], ETS.continuation()} | ETS.end_of_table()
Same as select/3
but unwraps or raises on error.
Specs
select_delete(t(), ETS.match_spec()) :: {:ok, non_neg_integer()} | {:error, any()}
Deletes records in the specified Set that match the specified match specification.
For more information on the match specification, see the erlang documentation
examples
Examples
iex> set = Set.new!(ordered: true)
iex> set
iex> |> Set.put!([{:a, :b, :c, :d}, {:e, :c, :f, :g}, {:h, :b, :c, :h}])
iex> |> Set.select_delete([{{:"$1", :b, :"$2", :_},[{:"==", :"$2", :c}],[true]}])
{:ok, 2}
iex> Set.to_list!(set)
[{:e, :c, :f, :g}]
Specs
select_delete!(t(), ETS.match_spec()) :: non_neg_integer()
Same as select_delete/2
but unwraps or raises on error.
Specs
Returns contents of table as a list.
examples
Examples
iex> Set.new!(ordered: true)
iex> |> Set.put!({:a, :b, :c})
iex> |> Set.put!({:d, :e, :f})
iex> |> Set.put!({:d, :e, :f})
iex> |> Set.to_list()
{:ok, [{:a, :b, :c}, {:d, :e, :f}]}
Specs
Same as to_list/1
but unwraps or raises on error.
Specs
Updates one or more elements within the record with the given key
. The element_spec is
a tuple (or list of tuples) of the form {position, value}
, which will update the element
at position
(1-indexed) to have the given value
. When a list is given, multiple elements
can be updated within the same record. If the same position occurs more than once in the list,
the last value in the list is written. If the list is empty or the function fails, no updates
are done. The function is also atomic in the sense that other processes can never see any
intermediate results.
Returns {:ok, set}
if an object with the given key is found, otherwise returns
{:error, :key_not_found}
.
examples
Examples
iex> set = Set.new!()
iex> Set.put!(set, {:a, :b, :c})
iex> Set.update_element(set, :a, {2, :d})
{:ok, set}
iex> Set.to_list!(set)
[{:a, :d, :c}]
iex> Set.update_element(set, :a, [{2, :x}, {3, :y}])
{:ok, set}
iex> Set.to_list!(set)
[{:a, :x, :y}]
Specs
Same as update_element/3
but unwraps or raises on error.
Specs
wrap_existing(ETS.table_identifier()) :: {:ok, t()} | {:error, any()}
Wraps an existing :ets :set or :ordered_set in a Set struct.
examples
Examples
iex> :ets.new(:my_ets_table, [:set, :named_table])
iex> {:ok, set} = Set.wrap_existing(:my_ets_table)
iex> Set.info!(set)[:name]
:my_ets_table
Specs
wrap_existing!(ETS.table_identifier()) :: t()
Same as wrap_existing/1
but unwraps or raises on error.