dynamic_rtree v0.2.0 Drtree View Source
This is the API module of the elixir r-tree implementation where you can do the basic actions.
Easy to use:
Starts a local r-tree named as Peter
iex> DDRT.start_link(%{name: Peter})
{:ok, #PID<0.214.0>}
Insert "Griffin" on r-tree named as Peter
iex> Drtree.insert({"Griffin",[{4,5},{6,7}]},Peter)
{:ok,
%{
43143342109176739 => {["Griffin"], nil, [{4, 5}, {6, 7}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{4, 5}, {6, 7}]}
}}
Insert "Parker" on r-tree named as Peter
iex> Drtree.insert({"Parker",[{10,11},{16,17}]},Peter)
{:ok,
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{4, 11}, {6, 17}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{4, 5}, {6, 7}]},
"Parker" => {:leaf, 43143342109176739, [{10, 11}, {16, 17}]}
}}
Query which leafs at Peter r-tree overlap with box [{0,7},{4,8}]
iex> Drtree.query([{0,7},{4,8}],Peter)
{:ok, ["Griffin"]}
Updates "Griffin" bounding box
iex> Drtree.update("Griffin",[{-6,-5},{11,12}],Peter)
{:ok,
%{
43143342109176739 => {["Parker", "Griffin"], nil, [{-6, 11}, {6, 17}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197],
"Griffin" => {:leaf, 43143342109176739, [{-6, -5}, {11, 12}]},
"Parker" => {:leaf, 43143342109176739, [{10, 11}, {16, 17}]}
}}
Repeat again the last query
iex> Drtree.query([{0,7},{4,8}],Peter)
{:ok, []} # Peter "Griffin" left the query bounding box
Let's punish them
iex> Drtree.delete(["Griffin","Parker"],Peter)
{:ok,
%{
43143342109176739 => {[], nil, [{0, 0}, {0, 0}]},
:root => 43143342109176739,
:ticket => [19125803434255161 | 82545666616502197]
}}
Easy concepts:
Bounding box format.
[{x_min,x_max},{y_min,y_max}]
Example: & & & & & y_max & & & & &
A unit at pos x: 10, y: -12 , & &
with x_size: 1 and y_size: 2 & &
would be represented with & pos &
the following bounding box x_min (x,y) x_max
[{9.5,10.5},{-13,-11}] & &
& &
& &
& & & & & y_min & & & & &
Link to this section Summary
Functions
Returns a specification to start this module under a supervisor.
Delete the leafs with the given ids
.
Insert leafs
at the r-tree named as 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
.
Get the r-tree representation
Update a single leaf bounding box
Update a bunch of r-tree leafs to the new bounding boxes defined.
Link to this section Types
Link to this section Functions
Returns a specification to start this module under a supervisor.
See Supervisor
.
Delete the leafs with the given ids
.
Returns {:ok,map()}
Parameters
ids
: Id or list of Id that you wanna delete.name
: the r-tree name where you wanna delete.
Examples
1 by 1.
iex> Drtree.delete("Griffin",Peter)
iex> Drtree.delete("Parker",Peter)
Bulk.
iex> Drtree.delete(["Griffin","Parker"],Peter)
Insert leafs
at the r-tree named as name
Returns {:ok,map()}
Parameters
leafs
: the data to insert.name
: the r-tree name where you wanna insert.
Examples
1 by 1.
iex> Drtree.insert({"Griffin",[{4,5},{6,7}]},Peter)
iex> Drtree.insert({"Parker",[{14,15},{16,17}]},Peter)
{: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.
iex> Drtree.insert([{"Griffin",[{4,5},{6,7}]},{"Parker",[{14,15},{16,17}]}],Peter)
{: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}]}
}}
Get the r-tree metadata
Returns map()
Examples
iex> Drtree.metadata(Peter)
%{
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
}
}
pquery(box, depth, name \\ __MODULE__)
View Sourcepquery(bounding_box(), integer(), atom()) :: [id()]
Query to get every node id overlapped by box
at the defined depth
.
Returns [id's]
.
query(box, name \\ __MODULE__)
View Sourcequery(bounding_box(), atom()) :: [id()]
Query to get every leaf id overlapped by box
.
Returns [id's]
.
Examples
iex> Drtree.query([{0,7},{4,8}],Peter)
{:ok, ["Griffin"]}
Get the r-tree representation
Returns map()
Examples
iex> Drtree.metadata(Peter)
%{
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 \\ __MODULE__)
View Sourceupdate(id(), bounding_box() | {bounding_box(), bounding_box()}, atom()) :: {:ok, map()}
Update a single leaf bounding box
Returns {:ok,map()}
Examples
iex> Drtree.update({"Griffin",[{0,1},{0,1}]},Peter)
{: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}]}
}}
Update a bunch of r-tree leafs to the new bounding boxes defined.
Returns {:ok,map()}
Examples
iex> Drtree.updates([{"Griffin",[{0,1},{0,1}]},{"Parker",[{10,11},{10,11}]}],Peter)
{: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}]}
}}