ex_shards v0.2.1 ExShards.Local

Local Shards API – This is the equivalent module to shards_local.

Examples

# create a table with default options
iex> ExShards.Local.new :mytab
:mytab

iex> ExShards.Local.insert :mytab, [k1: 1, k2: 2, k3: 3]
true

iex> for k <- [:k1, :k2, :k3] do
[{_, v}] = ExShards.Local.lookup(:mytab, k)
v
end
[1, 2, 3]

iex> ExShards.Local.delete :mytab, :k3
true
iex> ExShards.Local.lookup :mytab, :k3
[]

# let's create another table
iex> ExShards.Local.new :mytab2, [{:n_shards, 4}]
:mytab2

Link to this section Summary

Functions

Drops the given keys from tab

Fetches the value for a specific key in the given tab

Fetches the value for a specific key in the given tab, erroring out if tab doesn’t contain key

Gets the value or a list of values for a specific key in tab

Gets the value from key and updates it, all in one pass

Gets the value from key and updates it. Raises if there is no key

Returns whether the given key exists in the given tab

i()

Returns all keys from tab

Returns and removes the value(s) associated with key in tab

Puts the given value under key in tab

Puts the given value under key unless the entry key already exists in tab

Removes the entry in tab for a specific key

This function is analogous to :shards.insert/2,3, but it returns the table name instead of true

Drops the given keys from tab and returns a map with all dropped key-value pairs

Updates the key in tab with the given function

Updates key with the given function

This function is analogous to :shards.update_element/3,4, but it returns the table name instead of true

Returns all values from tab

Link to this section Functions

Link to this function delete(Elixir.arg1)
Link to this function delete(Elixir.arg1, Elixir.arg2)
Link to this function delete(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function delete_all_objects(Elixir.arg1)
Link to this function delete_all_objects(Elixir.arg1, Elixir.arg2)
Link to this function delete_object(Elixir.arg1, Elixir.arg2)
Link to this function delete_object(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function drop(tab, keys, state \\ ExShards.State.new())

Drops the given keys from tab.

If keys contains keys that are not in tab, they’re simply ignored.

Examples

iex> ExShards.set(:mytab, a: 1, b: 2, a: 3, c: 4)
iex> ExShards.drop(:mytab, [:a, :b, :e])
:mytab
iex> ExShards.keys(:mytab)
[:c]

Callback implementation for ExShards.Ext.drop/3.

Link to this function fetch(tab, key, state \\ ExShards.State.new())

Fetches the value for a specific key in the given tab.

If tab contains the given key with value value, then {:ok, value} is returned. If tab doesn’t contain key, :error is returned.

Keep in mind that only one result is returned always, in case of :bag or :duplicate bag, only the first match is returned.

Examples

iex> ExShards.fetch(:mytab, :a)
{:ok, 1}
iex> ExShards.fetch(:mytab, :b)
:error

Callback implementation for ExShards.Ext.fetch/3.

Link to this function fetch!(tab, key, state \\ ExShards.State.new())

Fetches the value for a specific key in the given tab, erroring out if tab doesn’t contain key.

If tab contains the given key, the corresponding value is returned. If tab doesn’t contain key, a KeyError exception is raised.

Keep in mind that only one result is returned always, in case of :bag or :duplicate bag, only the first match is returned.

Examples

iex> ExShards.fetch!(:mytab, :a)
1
iex> ExShards.fetch!(:mytab, :b)
** (KeyError) key :b not found in: :mytab

Callback implementation for ExShards.Ext.fetch!/3.

Link to this function file2tab(Elixir.arg1)
Link to this function file2tab(Elixir.arg1, Elixir.arg2)
Link to this function first(Elixir.arg1)
Link to this function first(Elixir.arg1, Elixir.arg2)
Link to this function foldl(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function foldl(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function foldr(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function foldr(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function get(tab, key, default \\ nil, state \\ ExShards.State.new())

Gets the value or a list of values for a specific key in tab.

Return possibilities:

  • value – If key is present in tab with value value (only one element matches).
  • [value] – In case of multiple elements matches with the key key. This behaviour is expected when the table is either a :bag or a :duplicate_bag.
  • default – If key is not present in tab (default is nil unless specified otherwise).

Examples

iex> ExShards.get(:mytab, :a)
nil
iex> :mytab |> ExShards.put(:a, 1) |> ExShards.get(:a)
1
iex> ExShards.get(:mytab, :b)
nil
iex> ExShards.get(:mytab, :b, 3)
3
iex> :mytab |> ExShards.set(c: 2, c: 3) |> ExShards.get(:c)
[2, 3]

Callback implementation for ExShards.Ext.get/4.

Link to this function get_and_update(tab, key, fun, state \\ ExShards.State.new())

Gets the value from key and updates it, all in one pass.

fun is called with the current value under key in tab (or nil if key is not present in tab) and must return a two-element tuple: the “get” value (the retrieved value, which can be operated on before being returned) and the new value to be stored under key. fun may also return :pop, which means the current value shall be removed from tab and returned (making this function behave like pop(tab, key).

The returned value is a tuple with the “get” value returned by fun and the new updated value under key.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.get(:a)
1

iex> ExShards.get_and_update(:mytab, :a, fn current_value ->
...>   {current_value, "new value!"}
...> end)
{1, "new value!"}

iex> ExShards.get_and_update(:mytab, :b, fn current_value ->
...>   {current_value, "new value!"}
...> end)
{nil, "new value!"}

iex> ExShards.get_and_update(:mytab, :a, fn _ -> :pop end)
{"new value!", nil}

iex> ExShards.get_and_update(:mytab, :b, fn _ -> :pop end)
{nil, nil}

Callback implementation for ExShards.Ext.get_and_update/4.

Link to this function get_and_update!(tab, key, fun, state \\ ExShards.State.new())

Gets the value from key and updates it. Raises if there is no key.

Behaves exactly like get_and_update/3, but raises a KeyError exception if key is not present in tab.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.get(:a)
1

iex> ExShards.get_and_update(:mytab, :a, fn current_value ->
...>   {current_value, "new value!"}
...> end)
{1, "new value!"}

iex> ExShards.get_and_update(:mytab, :b, fn current_value ->
...>   {current_value, "new value!"}
...> end)
** (KeyError) key :b not found in: :mytab

iex> ExShards.get_and_update(:mytab, :a, fn _ -> :pop end)
{"new value!", nil}

Callback implementation for ExShards.Ext.get_and_update!/4.

Link to this function give_away(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function give_away(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function has_key?(tab, key, state \\ ExShards.State.new())

Returns whether the given key exists in the given tab.

Examples

iex> ExShards.has_key?(:mytab, :a)
true
iex> ExShards.has_key?(:mytab, :b)
false

Callback implementation for ExShards.Ext.has_key?/3.

Link to this function info(Elixir.arg1)
Link to this function info(Elixir.arg1, Elixir.arg2)
Link to this function info(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function info_shard(Elixir.arg1)
Link to this function info_shard(Elixir.arg1, Elixir.arg2)
Link to this function insert(Elixir.arg1, Elixir.arg2)
Link to this function insert(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function insert_new(Elixir.arg1, Elixir.arg2)
Link to this function insert_new(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function is_compiled_ms(Elixir.arg1)
Link to this function keys(tab, state \\ ExShards.State.new())

Returns all keys from tab.

Examples

iex> ExShards.set(:mytab, a: 1, b: 2, c: 3)
:mytab
iex> ExShards.keys(:mytab)
[:a, :b, :c]

WARNING: This is an expensive operation, try DO NOT USE IT IN PROD.

Callback implementation for ExShards.Ext.keys/2.

Link to this function last(Elixir.arg1)
Link to this function last(Elixir.arg1, Elixir.arg2)
Link to this function lookup(Elixir.arg1, Elixir.arg2)
Link to this function lookup(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function lookup_element(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function lookup_element(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function match(Elixir.arg1)
Link to this function match(Elixir.arg1, Elixir.arg2)
Link to this function match(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function match(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function match_delete(Elixir.arg1, Elixir.arg2)
Link to this function match_delete(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function match_object(Elixir.arg1)
Link to this function match_object(Elixir.arg1, Elixir.arg2)
Link to this function match_object(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function match_object(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function match_spec_compile(Elixir.arg1)
Link to this function match_spec_run(Elixir.arg1, Elixir.arg2)
Link to this function member(Elixir.arg1, Elixir.arg2)
Link to this function member(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function next(Elixir.arg1, Elixir.arg2)
Link to this function next(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function pop(tab, key, default \\ nil, state \\ ExShards.State.new())

Returns and removes the value(s) associated with key in tab.

Return possibilities:

  • value – If key is present in tab with value value.
  • [value] – In case of multiple matches with the key key. This behaviour is expected when the table is either a :bag or a :duplicate_bag.
  • default – If key is not present in tab.

Examples

iex> :mytab |> ExShards.set(a: 1, b: 2, a: 2) |> ExShards.pop(:a)
[1, 2]
iex> ExShards.pop(:mytab, :b)
2
iex> ExShards.pop(:mytab, :c)
nil
iex> ExShards.pop(:mytab, :c, 3)
3

Callback implementation for ExShards.Ext.pop/4.

Link to this function prev(Elixir.arg1, Elixir.arg2)
Link to this function prev(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function put(tab, key, value, state \\ ExShards.State.new())

Puts the given value under key in tab.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.fetch!(:a)
1
iex> :mytab |> ExShards.put(:a, 3) |> ExShards.fetch!(:a)
3

Callback implementation for ExShards.Ext.put/4.

Link to this function put_new(tab, key, value, state \\ ExShards.State.new())

Puts the given value under key unless the entry key already exists in tab.

Examples

iex> ExShards.put_new(:mytab, :a, 1) |> ExShards.fetch!(:a)
1
iex> ExShards.put_new(:mytab, :a, 3) |> ExShards.fetch!(:a)
1

Callback implementation for ExShards.Ext.put_new/4.

Link to this function remove(tab, key, state \\ ExShards.State.new())

Removes the entry in tab for a specific key.

If the key does not exist, returns tab unchanged.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.fetch!(:a)
1
iex> ExShards.delete(:mytab, :a) |> ExShards.get(:a)
nil
iex> ExShards.delete(:mytab, :b) |> ExShards.get(:b)
nil

Callback implementation for ExShards.Ext.remove/3.

Link to this function rename(Elixir.arg1, Elixir.arg2)
Link to this function rename(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function safe_fixtable(Elixir.arg1, Elixir.arg2)
Link to this function safe_fixtable(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function select(Elixir.arg1)
Link to this function select(Elixir.arg1, Elixir.arg2)
Link to this function select(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function select(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function select_count(Elixir.arg1, Elixir.arg2)
Link to this function select_count(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function select_delete(Elixir.arg1, Elixir.arg2)
Link to this function select_delete(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function select_reverse(Elixir.arg1)
Link to this function select_reverse(Elixir.arg1, Elixir.arg2)
Link to this function select_reverse(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function select_reverse(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function set(tab, obj_or_objs, state \\ ExShards.State.new())

This function is analogous to :shards.insert/2,3, but it returns the table name instead of true.

Examples

iex> :mytab |> ExShards.set(a:1, b: 2) |> ExShards.get(:a)
1
iex> :mytab |> ExShards.set(b: 3) |> ExShards.get(:b)
3

Callback implementation for ExShards.Ext.set/3.

Link to this function setopts(Elixir.arg1, Elixir.arg2)
Link to this function setopts(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function tab2file(Elixir.arg1, Elixir.arg2)
Link to this function tab2file(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function tab2file(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function tab2list(Elixir.arg1)
Link to this function tab2list(Elixir.arg1, Elixir.arg2)
Link to this function tabfile_info(Elixir.arg1)
Link to this function table(Elixir.arg1)
Link to this function table(Elixir.arg1, Elixir.arg2)
Link to this function table(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function take(Elixir.arg1, Elixir.arg2)
Link to this function take(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function take_and_drop(tab, keys, state \\ ExShards.State.new())

Drops the given keys from tab and returns a map with all dropped key-value pairs.

If keys contains keys that are not in tab, they’re simply ignored.

Examples

iex> ExShards.set(:mytab, a: 1, b: 2, a: 3, c: 4)
iex> ExShards.take_and_drop(:mytab, [:a, :b, :e])
%{a: [1, 3], b: 2}
iex> ExShards.get(:mytab, :a)
nil

Callback implementation for ExShards.Ext.take_and_drop/3.

Link to this function test_ms(Elixir.arg1, Elixir.arg2)
Link to this function update(tab, key, initial, fun, state \\ ExShards.State.new())

Updates the key in tab with the given function.

If key is present in tab with value value, fun is invoked with argument value and its result is used as the new value of key. If key is not present in tab, initial is inserted as the value of key.

This functions only works for :set or :ordered_set tables.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.update(:a, 13, &(&1 * 2)) |> ExShards.get(:a)
2
iex> :mytab |> ExShards.update(:b, 11, &(&1 * 2)) |> ExShards.get(:b)
11

Callback implementation for ExShards.Ext.update/5.

Link to this function update!(tab, key, fun, state \\ ExShards.State.new())

Updates key with the given function.

If key is present in tab with value value, fun is invoked with argument value and its result is used as the new value of key. If key is not present in tab, a KeyError exception is raised.

This functions only works for :set or :ordered_set tables.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.update!(:a, &(&1 * 2)) |> ExShards.get(:a)
2
iex> :mytab |> ExShards.update(:b, &(&1 * 2))
** (KeyError) key :b not found in: :mytab

Callback implementation for ExShards.Ext.update!/4.

Link to this function update_counter(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function update_counter(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function update_counter(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4, Elixir.arg5)
Link to this function update_elem(tab, key, element_spec, state \\ ExShards.State.new())

This function is analogous to :shards.update_element/3,4, but it returns the table name instead of true.

This functions only works for :set or :ordered_set tables.

Examples

iex> :mytab |> ExShards.put(:a, 1) |> ExShards.update_elem(:a, {2, 11}) |> ExShards.get(:a)
11
iex> :mytab |> ExShards.update_elem(:b, {2, 22}) |> ExShards.get(:b)
nil

Callback implementation for ExShards.Ext.update_elem/4.

Link to this function update_element(Elixir.arg1, Elixir.arg2, Elixir.arg3)
Link to this function update_element(Elixir.arg1, Elixir.arg2, Elixir.arg3, Elixir.arg4)
Link to this function values(tab, state \\ ExShards.State.new())

Returns all values from tab.

Examples

iex> ExShards.set(:mytab, a: 1, b: 2, c: 3)
:mytab
iex> ExShards.values(:mytab)
[:a, :b, :c]

WARNING: This is an expensive operation, try DO NOT USE IT IN PROD.

Callback implementation for ExShards.Ext.values/2.