DR::R - Tarantool's RTREE implementation
use DR::R; my $tree = new DR::R dimension => 2, dist_type => 'EUCLID'; $tree->insert([1.2, 2.2], 1); $tree->insert([2.3, -2.1], 2); ... $tree->foreach(NEIGHBOR => [ 1, 2 ], sub { my ($p) = @_; print "%s is neighbour to [1:2]\n", $p; return 1; # continue iteration });
The module includes XS for tarantool RTREE index.
Point - is an array of numbers (double) with size=$dimension).
double
size=$dimension
Rect - is an array of numbers (double with size=2 * $dimension).
size=2 * $dimension
Index always uses Rect objects, so if You use points, index converts your points to rects.
my $point2d = [ $x, $y ]; my $point2d = [ $x, $y, $x, $y ]; # the same my $rect2d = [ $x1, $y1, $x2, $y2];
my $tree = DR::R->new(%opts);
Dimension for RTREE. Default value is 2. Can have value between 1 AND 20.
2
1
20
Algorithm to calc distance between objects. Default value is EUCLID. Can have value:
EUCLID
my $id = $tree->insert([1,2,3,4], $order);
Insert object to tree. Return object's index ID.
$tree->remove([1,2,3,4], $id);
Remove objects from tree. Return found object or undef.
undef
Iterate through tree.
$tree->foreach($TYPE, $point_or_rect, sub { my ($object) = @_; if (you_want_stop_iteration) { return 0; } else { return 1; } });
Iterators can have the following types:
Itearate records with the same rectangle.
Itearate nearest records from a given point (the point is acluattly lowest_point of given rectangle). Records are iterated in order of distance to given point. Yes, it is KNN iterator.
Itearate records that contain given rectangle.
Itearate records that strictly contain given rectangle.
Itearate records that overlaps with given rectangle.
Itearate records that belongs to given rectangle.
Itearate records that strictly belongs to given rectangle.
Itearate all records.
my $array_ref = $tree->select(NEIGHBOR => $point_or_rect, limit => $limit, offset => $offset );
Based on "foreach" select.
Run selected iterator until limit reached, since offset started. Default value for offset option is 0. There is no default value for limit option.
limit
offset
0
Dmitry E. Oboukhov, <unera@debian.org>
Copyright (C) 2017 by Dmitry E. Oboukhov (the perl module).
Tarantool is a collective effort, and incorporates many contributions from the community.
Below follows a list of people, who contributed their code.
Aleksandr Lyapunov, Aleksey Demakov, Aleksey Mashanov, Alexandre Kalendarev, Andrey Drozdov, Anton Barabanov, Damien Lefortier, Dmitry E. Oboukhov, Dmitry Simonenko, Elena Shebunyaeva, Eugene Blikh, Eugene Shadrin, Georgy Kirichenko, Konstantin Knizhnik, Konstantin Nazarov, Konstantin Osipov, Konstantin Shulgin, Mons Anderson, Marko Kevac, Nick Zavaritsky, Oleg Tsarev, Pavel Cherenkov, Roman Antipin, Roman Tokarev, Roman Tsisyk, Teodor Sigaev, Timofey Khryukin, Veniamin Gvozdikov, Vassiliy Soshnikov, Vladimir Rudnyh, Yuriy Nevinitsin, Yuriy Vostrikov.
Copyright 2010-2017 Tarantool authors.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY AUTHORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL AUTHORS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
To install DR::R, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DR::R
CPAN shell
perl -MCPAN -e shell install DR::R
For more information on module installation, please visit the detailed CPAN module installation guide.