ddrt v0.2.1 DDRT.DynamicRtree behaviour View Source
Use this module if you're interested in creating an R-Tree optimized to run on a single machine. If you'd instead like to run a distributed R-Tree on a cluster of Elixir nodes, use the DDRT module.
Link to this section Summary
Functions
Update a bunch of r-tree leaves to the new bounding boxes defined.
Returns a specification to start this module under a supervisor.
Delete the leaves with the given ids.
Insert leaves into the r-tree with process with name name
Get the r-tree metadata
Query to get every node id overlapped by box at the defined depth.
Query to get every leaf id overlapped by box.
Set the members of the DDRT cluster.
These are all of the possible configuration parameters for opts and their default values
Get the r-tree representation
Update a single leaf bounding box
Link to this section Types
tree_init()
View Sourcetree_init() :: [name: GenServer.name(), crdt: module(), conf: tree_config()]
Link to this section Functions
bulk_update(updates, name \\ DDRT)
View Sourcebulk_update(leaves :: [leaf()], name :: GenServer.name()) :: {:ok, map()}
Update a bunch of r-tree leaves to the new bounding boxes defined.
Returns {:ok,map()}
Examples
iex> DynamicRtree.bulk_update([{"Griffin",[{0,1},{0,1}]},{"Parker",[{10,11},{10,11}]}],:my_rtree)
{:ok,
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{0, 11}, {0, 11}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{0, 1}, {0, 1}]},
"Parker" => {:leaf, 43143342109176739, [{10, 11}, {10, 11}]}
}}
Returns a specification to start this module under a supervisor.
See Supervisor.
delete(ids, name \\ DDRT)
View Sourcedelete(ids :: id() | [id()], name :: GenServer.name()) :: {:ok, map()}
Delete the leaves with the given ids.
Returns {:ok,map()}
Parameters
ids: Id or list of Id that you want to delete.name: the name of the rtree process.
Examples
Individual deletion:
iex> DynamicRtree.delete("Griffin",:my_rtree)
iex> DynamicRtree.delete("Parker",:my_rtree)
Bulk Deletion:
iex> DynamicRtree.delete(["Griffin","Parker"],:my_rtree)
insert(leaves, name \\ DDRT)
View Sourceinsert(leaves :: leaf() | [leaf()], name :: GenServer.name()) :: {:ok, map()}
Insert leaves into the r-tree with process with name name
Returns {:ok,map()}
Parameters
leaves: the data to insert.name: the r-tree name where you want to insert.
Examples
Individual insertion:
iex> DynamicRtree.insert({"Griffin", [{4,5},{6,7}]}, :my_rtree)
iex> DynamicRtree.insert({"Parker", [{14,15},{16,17}]}, :my_rtree)
{:ok,
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{4, 15}, {6, 17}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{4, 5}, {6, 7}]},
"Parker" => {:leaf, 43143342109176739, [{14, 15}, {16, 17}]}
}}
Bulk Insertion:
iex> DynamicRtree.insert([{"Griffin", [{4,5},{6,7}]}, {"Parker", [{14,15},{16,17}]}], :my_rtree)
{:ok,
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{4, 15}, {6, 17}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{4, 5}, {6, 7}]},
"Parker" => {:leaf, 43143342109176739, [{14, 15}, {16, 17}]}
}}
metadata(name \\ DDRT)
View Sourcemetadata(name :: GenServer.name()) :: map()
Get the r-tree metadata
Returns map()
Examples
iex> DynamicRtree.metadata(:my_rtree)
%{
params: %{mode: :standalone, seed: 0, type: Map, verbose: false, width: 6},
seeding: %{
bits: 58,
jump: #Function<3.53802439/1 in :rand.mk_alg/1>,
next: #Function<0.53802439/1 in :rand.mk_alg/1>,
type: :exrop,
uniform: #Function<1.53802439/1 in :rand.mk_alg/1>,
uniform_n: #Function<2.53802439/2 in :rand.mk_alg/1>,
weak_low_bits: 1
}
}
new(opts \\ [width: 6, type: Map, mode: :standalone, verbose: false, seed: 0], name \\ DDRT)
View Sourcenew(opts :: Keyword.t(), name :: GenServer.name()) :: {:ok, map()}
pquery(box, depth, name \\ DDRT)
View Sourcepquery(box :: bounding_box(), depth :: integer(), name :: GenServer.name()) :: [ id() ]
Query to get every node id overlapped by box at the defined depth.
Returns [id's].
query(box, name \\ DDRT)
View Sourcequery(box :: bounding_box(), name :: GenServer.name()) :: [id()]
Query to get every leaf id overlapped by box.
Returns [id's].
Examples
iex> DynamicRtree.query([{0,7},{4,8}],:my_rtree)
{:ok, ["Griffin"]}
set_members(name, members)
View Sourceset_members(name :: GenServer.name(), [member()]) :: :ok
Set the members of the DDRT cluster.
members should be in the format {GenServer.name(), node()}.
Examples
DDRT.set_members(DDRT, [{DDRT.A, :yournode@foreignhost}, {DDRT.B, :yournode@foreignhost}])
These are all of the possible configuration parameters for opts and their default values:
- name: The name of the DDRT process. Defaults to
DDRT - width: The max number of children a node may have. Defaults to
6 - verbose: allows
Loggerto report console logs. (Also decreases performance). Defaults tofalse. - seed: Sets the seed value for the pseudo-random number generator which generates the unique IDs for each node in the tree. This is a deterministic process; so the same seed value will guarantee the same pseudo-random unique IDs being generated for your tree in the same order each time. Defaults to
0
Get the r-tree representation
Returns map()
Examples
iex> DynamicRtree.metadata(:my_rtree)
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{0, 11}, {0, 11}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{0, 1}, {0, 1}]},
"Parker" => {:leaf, 43143342109176739, [{10, 11}, {10, 11}]}
}
update(id, update, name \\ DDRT)
View Sourceupdate( ids :: id(), box :: bounding_box() | {bounding_box(), bounding_box()}, name :: GenServer.name() ) :: {:ok, map()}
Update a single leaf bounding box
Returns {:ok,map()}
Examples
iex> DynamicRtree.update({"Griffin",[{0,1},{0,1}]},:my_rtree)
{:ok,
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{0, 11}, {0, 11}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{0, 1}, {0, 1}]},
"Parker" => {:leaf, 43143342109176739, [{10, 11}, {16, 17}]}
}}
Link to this section Callbacks
bulk_update(leaves, name)
View Sourcebulk_update(leaves :: [leaf()], name :: GenServer.name()) :: {:ok, map()}
delete(ids, name)
View Sourcedelete(ids :: id() | [id()], name :: GenServer.name()) :: {:ok, map()}
insert(leaves, name)
View Sourceinsert(leaves :: leaf() | [leaf()], name :: GenServer.name()) :: {:ok, map()}
new(opts, name)
View Sourcenew(opts :: Keyword.t(), name :: GenServer.name()) :: {:ok, map()}
pquery(box, depth, name)
View Sourcepquery(box :: bounding_box(), depth :: integer(), name :: GenServer.name()) :: [ id() ]
query(box, name)
View Sourcequery(box :: bounding_box(), name :: GenServer.name()) :: [id()]
set_members(name, list)
View Sourceset_members(name :: GenServer.name(), [member()]) :: :ok
update(ids, box, name)
View Sourceupdate( ids :: id(), box :: bounding_box() | {bounding_box(), bounding_box()}, name :: GenServer.name() ) :: {:ok, map()}