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
atomics_ref()
View Source
atomics_ref() :: :atomics.atomics_ref()
atomics_ref() :: :atomics.atomics_ref()
t()
View Source
t() :: t_for_ane_mode() | t_for_ets_mode()
t() :: t_for_ane_mode() | t_for_ets_mode()
t_for_ane_mode()
View Source
t_for_ane_mode() :: {tid(), atomics_ref(), atomics_ref(), map()}
t_for_ane_mode() :: {tid(), atomics_ref(), atomics_ref(), map()}
t_for_ets_mode()
View Source
t_for_ets_mode() :: {tid(), pos_integer()}
t_for_ets_mode() :: {tid(), pos_integer()}
tid()
View Source
tid() :: :ets.tid()
tid() :: :ets.tid()
Link to this section Functions
clear(ane)
View Source
clear(t()) :: :ok
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
destroy(ane)
View Source
destroy(t()) :: :ok
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
destroyed?(ane) View Source
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
get(ane, i)
View Source
get(t(), pos_integer()) :: {t(), any()}
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"
get_mode(ane)
View Source
get_mode(t()) :: :ane | :ets
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
get_size(ane)
View Source
get_size(t()) :: pos_integer()
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
get_table(ane) View Source
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
new(size, options \\ [])
View Source
new(pos_integer(), keyword()) :: t()
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 tofalse
.:write_concurrency
(boolean) - set write_concurrency for underneath ETS table. Default tofalse
.:compressed
(boolean) - set compressed for underneath ETS table. Default tofalse
.
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
put(ane, i, value)
View Source
put(t(), pos_integer(), any()) :: :ok
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"