NAME

DR::R - Tarantool's RTREE implementation

SYNOPSIS

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
});

DESCRIPTION

The module includes XS for tarantool RTREE index.

Points and Rects

Point - is an array of numbers (double) with size=$dimension).

Rect - is an array of numbers (double with size=2 * $dimension).

Index always uses Rect objects, so if You use points, index converts your points to rects.

Examples

my $point2d = [ $x, $y ];
my $point2d = [ $x, $y, $x, $y ]; # the same


my $rect2d = [ $x1, $y1, $x2, $y2];

METHODS

new (constructor)

my $tree = DR::R->new(%opts);

Constructor options.

dimension

Dimension for RTREE. Default value is 2. Can have value between 1 AND 20.

dist_type

Algorithm to calc distance between objects. Default value is EUCLID. Can have value:

EUCLID
MANHATTAN

insert

my $id = $tree->insert([1,2,3,4], $order);

Insert object to tree. Return object's index ID.

remove

$tree->remove([1,2,3,4], $id);

Remove objects from tree. Return found object or undef.

foreach

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:

EQ

Itearate records with the same rectangle.

NEIGHBOR

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.

CONTAINS

Itearate records that contain given rectangle.

CONTAINS!

Itearate records that strictly contain given rectangle.

OVERLAPS

Itearate records that overlaps with given rectangle.

BELONGS

Itearate records that belongs to given rectangle.

BELONGS!

Itearate records that strictly belongs to given rectangle.

ALL

Itearate all records.

AUTHOR

Dmitry E. Oboukhov, <unera@debian.org>

COPYRIGHT AND LICENSE

Copyright (C) 2017 by Dmitry E. Oboukhov (the perl bindings).

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:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

  2. 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.