XEts.KV (x_ets v0.2.0)
A module for working with ETS tables.
This module is a wrapper around the :shards
module which is provides
a high level of concurrency and scalability without the need for locks.
Supports the Access protocol for getting and setting values.
Link to this section Summary
Functions
Delete an item from the table.
Delete all items from the table.
Get an item from the table.
Get an item from the table.
Get and update an item in the table.
Get information about the table.
Get information about a key in the table.
Get an item from the table.
Delete an item or items from the table.
Test if key is a member.
Pop an item from the table.
Put one or more items into the table.
Put an item into the table.
Put one or more new items into the table.
Put an item into the table if it doesn't exist.
Convert the table to a list.
Link to this section Types
Specs
t() :: %XEts.KV{tab: atom()}
tab()
Specs
Link to this section Functions
delete(t, key)
Specs
Delete an item from the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.delete(:k) |> XEts.KV.to_list()
[]
delete_all(t)
Specs
Delete all items from the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.delete_all() |> XEts.KV.to_list()
[]
fetch(tab, key)
Specs
Get an item from the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.fetch(:k)
{:ok, :v}
iex> XEts.KV.new(:foo, []) |> XEts.KV.fetch(:k)
:error
get(tab, value, default \\ nil)
Specs
Get an item from the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.get(:k)
:v
get_and_update(tab, key, fun)
Specs
Get and update an item in the table.
iex> tab = XEts.KV.new(:foo, []) |> XEts.KV.put(:k, 2)
iex> XEts.KV.get_and_update(tab, :k, & { &1, &1 + 1 })
{2, tab}
info(map)
Specs
Get information about the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.info() |> length()
18
info(map, key)
Get information about a key in the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.info(:name)
:foo
match(tab, key, wildcard \\ :"$2", default \\ [])
Specs
Get an item from the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.get(:k)
:v
match_delete(tab, match_spec)
Specs
Delete an item or items from the table.
iex> XEts.KV.new(:foo, []) |>
...> XEts.KV.put(:k, :v) |>
...> XEts.KV.match_delete({:_, :_}) |>
...> XEts.KV.to_list()
[]
member?(tab, key)
Specs
Test if key is a member.
iex> :foo |> XEts.KV.new([]) |> XEts.KV.put(:x, nil) |> XEts.KV.member?(:x)
true
iex> :bar |> XEts.KV.new([]) |> XEts.KV.member?(:x)
false
new(tab, opts \\ [:named_table, parallel: true, read_concurrency: true, write_concurrency: true])
Specs
pop(tab, key, default \\ nil)
Specs
Pop an item from the table.
iex> tab = XEts.KV.new(:foo, [])
iex> tab |> XEts.KV.put(:k, :v) |> XEts.KV.pop(:k)
{:v, tab}
put(t, item_or_items)
Specs
Put one or more items into the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put({:k, :v}) |> XEts.KV.to_list()
[{:k, :v}]
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(k: :v, k2: :v2) |> XEts.KV.to_list()
[{:k, :v}, {:k2, :v2}]
put(t, key, value)
Specs
Put an item into the table.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.to_list()
[{:k, :v}]
put_new(tab, item_or_items)
Specs
Put one or more new items into the table.
iex> XEts.KV.new(:foo, []) |>
...> XEts.KV.put({:k, :v}) |>
...> XEts.KV.put_new(:k, :v2) |>
...> XEts.KV.to_list()
[{:k, :v}]
iex> XEts.KV.new(:foo, []) |>
...> XEts.KV.put(k: :v, k2: :v2) |>
...> XEts.KV.put_new([k: :v3, k2: :vv]) |>
...>XEts.KV.to_list()
[{:k, :v}, {:k2, :v2}]
put_new(tab, key, value)
Put an item into the table if it doesn't exist.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put_new(:k, :v) |> XEts.KV.to_list()
[{:k, :v}]
to_list(map)
Specs
Convert the table to a list.
iex> XEts.KV.new(:foo, []) |> XEts.KV.put(:k, :v) |> XEts.KV.to_list()
[{:k, :v}]