Ane v0.1.1 Ane View Source

A very efficient way to share mutable data by utilizing :atomics and :ets modules.

github.com/gyson/ane has detailed guides.

Link to this section Summary

Functions

Clear garbage data which could be generated when Ane.put is interrupted

Destroy an Ane instance

Check if Ane instance is destroyed

Get value at one-based index in Ane instance

Get mode of Ane instance

Get size of Ane instance

Get ETS table of Ane instance

Create and return an Ane instance

Put value at one-based index in Ane instance

Link to this section Types

Link to this section Functions

Link to this function

clear(ane) View Source
clear(t()) :: :ok

Clear garbage data which could be generated when Ane.put is interrupted.

Example

iex> a = Ane.new(1)
iex> Ane.clear(a)
:ok
Link to this function

destroy(ane) View Source
destroy(t()) :: :ok

Destroy an Ane instance.

Example

iex> a = Ane.new(1)
iex> Ane.destroyed?(a)
false
iex> Ane.destroy(a)
:ok
iex> Ane.destroyed?(a)
true
Link to this function

destroyed?(ane) View Source
destroyed?(t()) :: boolean()

Check if Ane instance is destroyed.

Example

iex> a = Ane.new(1)
iex> Ane.destroyed?(a)
false
iex> Ane.destroy(a)
:ok
iex> Ane.destroyed?(a)
true
Link to this function

get(ane, i) View Source
get(t(), pos_integer()) :: {t(), any()}

Get value at one-based index in Ane instance.

It returns a tuple with two elements:

  • First element is new Ane instance which includes latest cached data.

    • Note: we need to use this returned new Ane instance for following read operations to make cache work properly.
  • Second element is the value at one-based index. Value is initialized as nil by default.

Example

iex> a = Ane.new(1)
iex> {a, value} = Ane.get(a, 1)
iex> value
nil
iex> Ane.put(a, 1, "hello")
:ok
iex> {_, value} = Ane.get(a, 1)
iex> value
"hello"
Link to this function

get_mode(ane) View Source
get_mode(t()) :: :ane | :ets

Get mode of Ane instance.

Example

iex> Ane.new(1) |> Ane.get_mode()
:ane
iex> Ane.new(1, mode: :ane) |> Ane.get_mode()
:ane
iex> Ane.new(1, mode: :ets) |> Ane.get_mode()
:ets
Link to this function

get_size(ane) View Source
get_size(t()) :: pos_integer()

Get size of Ane instance.

Example

iex> Ane.new(1) |> Ane.get_size()
1
iex> Ane.new(10) |> Ane.get_size()
10
Link to this function

get_table(ane) View Source
get_table(t()) :: tid()

Get ETS table of Ane instance.

The returned ETS table could be used to

  • get more info via :ets.info
  • change ownership via :ets.give_away
  • change configuration via :ets.setopts

Example

iex> Ane.new(1) |> Ane.get_table() |> :ets.info(:type)
:set
Link to this function

new(size, options \\ []) View Source
new(pos_integer(), keyword()) :: t()

Create and return an Ane instance.

Options

  • :mode (atom) - set mode of Ane instance. Default to :ane.
  • :read_concurrency (boolean) - set read_concurrency for underneath ETS table. Default to false.
  • :write_concurrency (boolean) - set write_concurrency for underneath ETS table. Default to false.
  • :compressed (boolean) - set compressed for underneath ETS table. Default to false.

Example

iex> a = Ane.new(1, read_concurrency: false, write_concurrency: false, compressed: false)
iex> t = Ane.get_table(a)
iex> :ets.info(t, :read_concurrency)
false
iex> :ets.info(t, :write_concurrency)
false
iex> :ets.info(t, :compressed)
false
Link to this function

put(ane, i, value) View Source
put(t(), pos_integer(), any()) :: :ok

Put value at one-based index in Ane instance.

It would always return :ok.

Ane.put includes one :ets.insert operation and one :ets.delete operation. When the process running Ane.put is interrupted (e.g. by :erlang.exit(pid, :kill)), garbage data could be generated if it finished insert operation but did not start delete operation. These garbabge data could be removed by Ane.clear.

Example

iex> a = Ane.new(1)
iex> {a, value} = Ane.get(a, 1)
iex> value
nil
iex> Ane.put(a, 1, "world")
:ok
iex> {_, value} = Ane.get(a, 1)
iex> value
"world"