-
Notifications
You must be signed in to change notification settings - Fork 214
/
rtree.hpp
2389 lines (1897 loc) · 79.4 KB
/
rtree.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Boost.Geometry Index
//
// R-tree implementation
//
// Copyright (c) 2008 Federico J. Fernandez.
// Copyright (c) 2011-2019 Adam Wulkiewicz, Lodz, Poland.
// Copyright (c) 2020 Caian Benedicto, Campinas, Brazil.
//
// This file was modified by Oracle on 2019-2021.
// Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
//
// Use, modification and distribution is subject to the Boost Software License,
// Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
#ifndef BOOST_GEOMETRY_INDEX_RTREE_HPP
#define BOOST_GEOMETRY_INDEX_RTREE_HPP
// STD
#include <algorithm>
#include <type_traits>
// Boost
#include <boost/container/new_allocator.hpp>
#include <boost/move/move.hpp>
#include <boost/tuple/tuple.hpp>
// Boost.Geometry
#include <boost/geometry/core/static_assert.hpp>
#include <boost/geometry/algorithms/detail/comparable_distance/interface.hpp>
#include <boost/geometry/algorithms/detail/covered_by/interface.hpp>
#include <boost/geometry/algorithms/detail/disjoint/interface.hpp>
#include <boost/geometry/algorithms/detail/equals/interface.hpp>
#include <boost/geometry/algorithms/detail/intersects/interface.hpp>
#include <boost/geometry/algorithms/detail/overlaps/interface.hpp>
#include <boost/geometry/algorithms/detail/touches/interface.hpp>
#include <boost/geometry/algorithms/detail/within/interface.hpp>
#include <boost/geometry/algorithms/centroid.hpp>
#include <boost/geometry/geometries/point.hpp>
#include <boost/geometry/geometries/box.hpp>
// Boost.Geometry.Index
#include <boost/geometry/index/detail/config_begin.hpp>
#include <boost/geometry/index/detail/assert.hpp>
#include <boost/geometry/index/detail/exception.hpp>
#include <boost/geometry/index/detail/rtree/options.hpp>
#include <boost/geometry/index/indexable.hpp>
#include <boost/geometry/index/equal_to.hpp>
#include <boost/geometry/index/detail/translator.hpp>
#include <boost/geometry/index/predicates.hpp>
#include <boost/geometry/index/distance_predicates.hpp>
#include <boost/geometry/index/detail/rtree/adaptors.hpp>
#include <boost/geometry/index/detail/meta.hpp>
#include <boost/geometry/index/detail/utilities.hpp>
#include <boost/geometry/index/detail/rtree/node/node.hpp>
#include <boost/geometry/index/detail/algorithms/is_valid.hpp>
#include <boost/geometry/index/detail/rtree/visitors/insert.hpp>
#include <boost/geometry/index/detail/rtree/visitors/iterator.hpp>
#include <boost/geometry/index/detail/rtree/visitors/remove.hpp>
#include <boost/geometry/index/detail/rtree/visitors/copy.hpp>
#include <boost/geometry/index/detail/rtree/visitors/destroy.hpp>
#include <boost/geometry/index/detail/rtree/visitors/spatial_query.hpp>
#include <boost/geometry/index/detail/rtree/visitors/distance_query.hpp>
#include <boost/geometry/index/detail/rtree/visitors/count.hpp>
#include <boost/geometry/index/detail/rtree/visitors/children_box.hpp>
#include <boost/geometry/index/detail/rtree/linear/linear.hpp>
#include <boost/geometry/index/detail/rtree/quadratic/quadratic.hpp>
#include <boost/geometry/index/detail/rtree/rstar/rstar.hpp>
//#include <boost/geometry/extensions/index/detail/rtree/kmeans/kmeans.hpp>
#include <boost/geometry/index/detail/rtree/pack_create.hpp>
#include <boost/geometry/index/inserter.hpp>
#include <boost/geometry/index/detail/rtree/utilities/view.hpp>
#include <boost/geometry/index/detail/rtree/iterators.hpp>
#include <boost/geometry/index/detail/rtree/query_iterators.hpp>
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
// serialization
#include <boost/geometry/index/detail/serialization.hpp>
#endif
#include <boost/geometry/util/range.hpp>
#include <boost/geometry/util/type_traits.hpp>
// TODO change the name to bounding_tree
/*!
\defgroup rtree_functions R-tree free functions (boost::geometry::index::)
*/
namespace boost { namespace geometry { namespace index {
/*!
\brief The R-tree spatial index.
This is self-balancing spatial index capable to store various types of Values
and balancing algorithms.
\par Parameters
The user must pass a type defining the Parameters which will
be used in rtree creation process. This type is used e.g. to specify balancing
algorithm with specific parameters like min and max number of elements in node.
\par
Predefined algorithms with compile-time parameters are:
\li <tt>boost::geometry::index::linear</tt>,
\li <tt>boost::geometry::index::quadratic</tt>,
\li <tt>boost::geometry::index::rstar</tt>.
\par
Predefined algorithms with run-time parameters are:
\li \c boost::geometry::index::dynamic_linear,
\li \c boost::geometry::index::dynamic_quadratic,
\li \c boost::geometry::index::dynamic_rstar.
\par IndexableGetter
The object of IndexableGetter type translates from Value to Indexable each time
r-tree requires it. This means that this operation is done for each Value
access. Therefore the IndexableGetter should return the Indexable by
a reference type. The Indexable should not be calculated since it could harm
the performance. The default IndexableGetter can translate all types adapted
to Point, Box or Segment concepts (called Indexables). Furthermore, it can
handle <tt>std::pair<Indexable, T></tt>, <tt>std::tuple<Indexable, ...></tt>
and <tt>boost::tuple<Indexable, ...></tt>. For example, for Value
of type <tt>std::pair<Box, int></tt>, the default IndexableGetter translates
from <tt>std::pair<Box, int> const&</tt> to <tt>Box const&</tt>.
\par EqualTo
The object of EqualTo type compares Values and returns <tt>true</tt> if they
are equal. It's similar to <tt>std::equal_to<></tt>. The default EqualTo
returns the result of <tt>boost::geometry::equals()</tt> for types adapted to
some Geometry concept defined in Boost.Geometry and the result of
<tt>operator==</tt> for other types. Components of Pairs and Tuples are
compared left-to-right.
\tparam Value The type of objects stored in the container.
\tparam Parameters Compile-time parameters.
\tparam IndexableGetter The function object extracting Indexable from Value.
\tparam EqualTo The function object comparing objects of type Value.
\tparam Allocator The allocator used to allocate/deallocate memory,
construct/destroy nodes and Values.
*/
template
<
typename Value,
typename Parameters,
typename IndexableGetter = index::indexable<Value>,
typename EqualTo = index::equal_to<Value>,
typename Allocator = boost::container::new_allocator<Value>
>
class rtree
{
BOOST_COPYABLE_AND_MOVABLE(rtree)
public:
/*! \brief The type of Value stored in the container. */
typedef Value value_type;
/*! \brief R-tree parameters type. */
typedef Parameters parameters_type;
/*! \brief The function object extracting Indexable from Value. */
typedef IndexableGetter indexable_getter;
/*! \brief The function object comparing objects of type Value. */
typedef EqualTo value_equal;
/*! \brief The type of allocator used by the container. */
typedef Allocator allocator_type;
// TODO: SHOULD THIS TYPE BE REMOVED?
/*! \brief The Indexable type to which Value is translated. */
typedef typename index::detail::indexable_type<
detail::translator<IndexableGetter, EqualTo>
>::type indexable_type;
/*! \brief The Box type used by the R-tree. */
typedef geometry::model::box<
geometry::model::point<
typename coordinate_type<indexable_type>::type,
dimension<indexable_type>::value,
typename coordinate_system<indexable_type>::type
>
>
bounds_type;
private:
typedef bounds_type box_type;
struct members_holder
: public detail::translator<IndexableGetter, EqualTo>
, public Parameters
, public detail::rtree::allocators
<
Allocator,
Value,
Parameters,
bounds_type,
typename detail::rtree::options_type<Parameters>::type::node_tag
>
{
typedef Value value_type;
typedef typename rtree::bounds_type bounds_type;
typedef Parameters parameters_type;
//typedef IndexableGetter indexable_getter;
//typedef EqualTo value_equal;
//typedef Allocator allocator_type;
typedef bounds_type box_type;
typedef detail::translator<IndexableGetter, EqualTo> translator_type;
typedef typename detail::rtree::options_type<Parameters>::type options_type;
typedef typename options_type::node_tag node_tag;
typedef detail::rtree::allocators
<
Allocator, Value, Parameters, bounds_type, node_tag
> allocators_type;
typedef typename detail::rtree::node
<
value_type, parameters_type, bounds_type, allocators_type, node_tag
>::type node;
typedef typename detail::rtree::internal_node
<
value_type, parameters_type, bounds_type, allocators_type, node_tag
>::type internal_node;
typedef typename detail::rtree::leaf
<
value_type, parameters_type, bounds_type, allocators_type, node_tag
>::type leaf;
// TODO: only one visitor type is needed
typedef typename detail::rtree::visitor
<
value_type, parameters_type, bounds_type, allocators_type, node_tag, false
>::type visitor;
typedef typename detail::rtree::visitor
<
value_type, parameters_type, bounds_type, allocators_type, node_tag, true
>::type visitor_const;
typedef typename allocators_type::node_pointer node_pointer;
typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
typedef typename allocators_type::size_type size_type;
private:
members_holder(members_holder const&);
members_holder & operator=(members_holder const&);
public:
template <typename IndGet, typename ValEq, typename Alloc>
members_holder(IndGet const& ind_get,
ValEq const& val_eq,
Parameters const& parameters,
BOOST_FWD_REF(Alloc) alloc)
: translator_type(ind_get, val_eq)
, Parameters(parameters)
, allocators_type(boost::forward<Alloc>(alloc))
, values_count(0)
, leafs_level(0)
, root(0)
{}
template <typename IndGet, typename ValEq>
members_holder(IndGet const& ind_get,
ValEq const& val_eq,
Parameters const& parameters)
: translator_type(ind_get, val_eq)
, Parameters(parameters)
, allocators_type()
, values_count(0)
, leafs_level(0)
, root(0)
{}
translator_type const& translator() const { return *this; }
IndexableGetter const& indexable_getter() const { return *this; }
IndexableGetter & indexable_getter() { return *this; }
EqualTo const& equal_to() const { return *this; }
EqualTo & equal_to() { return *this; }
Parameters const& parameters() const { return *this; }
Parameters & parameters() { return *this; }
allocators_type const& allocators() const { return *this; }
allocators_type & allocators() { return *this; }
size_type values_count;
size_type leafs_level;
node_pointer root;
};
typedef typename members_holder::translator_type translator_type;
typedef typename members_holder::options_type options_type;
typedef typename members_holder::allocators_type allocators_type;
typedef typename members_holder::node node;
typedef typename members_holder::internal_node internal_node;
typedef typename members_holder::leaf leaf;
typedef typename members_holder::node_pointer node_pointer;
typedef typename members_holder::allocator_traits_type allocator_traits_type;
friend class detail::rtree::utilities::view<rtree>;
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
friend class detail::rtree::private_view<rtree>;
friend class detail::rtree::const_private_view<rtree>;
#endif
public:
/*! \brief Type of reference to Value. */
typedef typename allocators_type::reference reference;
/*! \brief Type of reference to const Value. */
typedef typename allocators_type::const_reference const_reference;
/*! \brief Type of pointer to Value. */
typedef typename allocators_type::pointer pointer;
/*! \brief Type of pointer to const Value. */
typedef typename allocators_type::const_pointer const_pointer;
/*! \brief Type of difference type. */
typedef typename allocators_type::difference_type difference_type;
/*! \brief Unsigned integral type used by the container. */
typedef typename allocators_type::size_type size_type;
/*! \brief Type of const iterator, category ForwardIterator. */
typedef index::detail::rtree::iterators::iterator
<
value_type, options_type, translator_type, box_type, allocators_type
> const_iterator;
/*! \brief Type of const query iterator, category ForwardIterator. */
typedef index::detail::rtree::iterators::query_iterator
<
value_type, allocators_type
> const_query_iterator;
public:
/*!
\brief The constructor.
\param parameters The parameters object.
\param getter The function object extracting Indexable from Value.
\param equal The function object comparing Values.
\par Throws
If allocator default constructor throws.
*/
inline explicit rtree(parameters_type const& parameters = parameters_type(),
indexable_getter const& getter = indexable_getter(),
value_equal const& equal = value_equal())
: m_members(getter, equal, parameters)
{}
/*!
\brief The constructor.
\param parameters The parameters object.
\param getter The function object extracting Indexable from Value.
\param equal The function object comparing Values.
\param allocator The allocator object.
\par Throws
If allocator copy constructor throws.
*/
inline rtree(parameters_type const& parameters,
indexable_getter const& getter,
value_equal const& equal,
allocator_type const& allocator)
: m_members(getter, equal, parameters, allocator)
{}
/*!
\brief The constructor.
The tree is created using packing algorithm.
\param first The beginning of the range of Values.
\param last The end of the range of Values.
\param parameters The parameters object.
\param getter The function object extracting Indexable from Value.
\param equal The function object comparing Values.
\param allocator The allocator object.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Iterator>
inline rtree(Iterator first, Iterator last,
parameters_type const& parameters = parameters_type(),
indexable_getter const& getter = indexable_getter(),
value_equal const& equal = value_equal(),
allocator_type const& allocator = allocator_type())
: m_members(getter, equal, parameters, allocator)
{
pack_construct(first, last, boost::container::new_allocator<void>());
}
/*!
\brief The constructor.
The tree is created using packing algorithm.
\param rng The range of Values.
\param parameters The parameters object.
\param getter The function object extracting Indexable from Value.
\param equal The function object comparing Values.
\param allocator The allocator object.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Range>
inline explicit rtree(Range const& rng,
parameters_type const& parameters = parameters_type(),
indexable_getter const& getter = indexable_getter(),
value_equal const& equal = value_equal(),
allocator_type const& allocator = allocator_type())
: m_members(getter, equal, parameters, allocator)
{
pack_construct(::boost::begin(rng), ::boost::end(rng), boost::container::new_allocator<void>());
}
/*!
\brief The constructor.
The tree is created using packing algorithm and a temporary packing allocator.
\param first The beginning of the range of Values.
\param last The end of the range of Values.
\param parameters The parameters object.
\param getter The function object extracting Indexable from Value.
\param equal The function object comparing Values.
\param allocator The allocator object for persistent data in the tree.
\param temp_allocator The temporary allocator object used when packing.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Iterator, typename PackAlloc>
inline rtree(Iterator first, Iterator last,
parameters_type const& parameters,
indexable_getter const& getter,
value_equal const& equal,
allocator_type const& allocator,
PackAlloc const& temp_allocator)
: m_members(getter, equal, parameters, allocator)
{
pack_construct(first, last, temp_allocator);
}
/*!
\brief The constructor.
The tree is created using packing algorithm and a temporary packing allocator.
\param rng The range of Values.
\param parameters The parameters object.
\param getter The function object extracting Indexable from Value.
\param equal The function object comparing Values.
\param allocator The allocator object for persistent data in the tree.
\param temp_allocator The temporary allocator object used when packing.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Range, typename PackAlloc>
inline explicit rtree(Range const& rng,
parameters_type const& parameters,
indexable_getter const& getter,
value_equal const& equal,
allocator_type const& allocator,
PackAlloc const& temp_allocator)
: m_members(getter, equal, parameters, allocator)
{
pack_construct(::boost::begin(rng), ::boost::end(rng), temp_allocator);
}
/*!
\brief The constructor.
The tree is created using packing algorithm and a temporary packing allocator.
\param first The beginning of the range of Values.
\param last The end of the range of Values.
\param allocator The allocator object for persistent data in the tree.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Iterator>
inline rtree(Iterator first, Iterator last,
allocator_type const& allocator)
: m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
{
pack_construct(first, last, boost::container::new_allocator<void>());
}
/*!
\brief The constructor.
The tree is created using packing algorithm and a temporary packing allocator.
\param rng The range of Values.
\param allocator The allocator object for persistent data in the tree.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Range>
inline explicit rtree(Range const& rng,
allocator_type const& allocator)
: m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
{
pack_construct(::boost::begin(rng), ::boost::end(rng), boost::container::new_allocator<void>());
}
/*!
\brief The constructor.
The tree is created using packing algorithm and a temporary packing allocator.
\param first The beginning of the range of Values.
\param last The end of the range of Values.
\param allocator The allocator object for persistent data in the tree.
\param temp_allocator The temporary allocator object used when packing.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Iterator, typename PackAlloc>
inline rtree(Iterator first, Iterator last,
allocator_type const& allocator,
PackAlloc const& temp_allocator)
: m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
{
pack_construct(first, last, temp_allocator);
}
/*!
\brief The constructor.
The tree is created using packing algorithm and a temporary packing allocator.
\param rng The range of Values.
\param allocator The allocator object for persistent data in the tree.
\param temp_allocator The temporary allocator object used when packing.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
*/
template<typename Range, typename PackAlloc>
inline explicit rtree(Range const& rng,
allocator_type const& allocator,
PackAlloc const& temp_allocator)
: m_members(indexable_getter(), value_equal(), parameters_type(), allocator)
{
pack_construct(::boost::begin(rng), ::boost::end(rng), temp_allocator);
}
/*!
\brief The destructor.
\par Throws
Nothing.
*/
inline ~rtree()
{
this->raw_destroy(*this);
}
/*!
\brief The copy constructor.
It uses parameters, translator and allocator from the source tree.
\param src The rtree which content will be copied.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor throws.
\li If allocation throws or returns invalid value.
*/
inline rtree(rtree const& src)
: m_members(src.m_members.indexable_getter(),
src.m_members.equal_to(),
src.m_members.parameters(),
allocator_traits_type::select_on_container_copy_construction(src.get_allocator()))
{
this->raw_copy(src, *this, false);
}
/*!
\brief The copy constructor.
It uses Parameters and translator from the source tree.
\param src The rtree which content will be copied.
\param allocator The allocator which will be used.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor throws.
\li If allocation throws or returns invalid value.
*/
inline rtree(rtree const& src, allocator_type const& allocator)
: m_members(src.m_members.indexable_getter(),
src.m_members.equal_to(),
src.m_members.parameters(), allocator)
{
this->raw_copy(src, *this, false);
}
/*!
\brief The moving constructor.
It uses parameters, translator and allocator from the source tree.
\param src The rtree which content will be moved.
\par Throws
Nothing.
*/
inline rtree(BOOST_RV_REF(rtree) src)
: m_members(src.m_members.indexable_getter(),
src.m_members.equal_to(),
src.m_members.parameters(),
boost::move(src.m_members.allocators()))
{
boost::swap(m_members.values_count, src.m_members.values_count);
boost::swap(m_members.leafs_level, src.m_members.leafs_level);
boost::swap(m_members.root, src.m_members.root);
}
/*!
\brief The moving constructor.
It uses parameters and translator from the source tree.
\param src The rtree which content will be moved.
\param allocator The allocator.
\par Throws
\li If allocator copy constructor throws.
\li If Value copy constructor throws (only if allocators aren't equal).
\li If allocation throws or returns invalid value (only if allocators aren't equal).
*/
inline rtree(BOOST_RV_REF(rtree) src, allocator_type const& allocator)
: m_members(src.m_members.indexable_getter(),
src.m_members.equal_to(),
src.m_members.parameters(),
allocator)
{
if ( src.m_members.allocators() == allocator )
{
boost::swap(m_members.values_count, src.m_members.values_count);
boost::swap(m_members.leafs_level, src.m_members.leafs_level);
boost::swap(m_members.root, src.m_members.root);
}
else
{
this->raw_copy(src, *this, false);
}
}
/*!
\brief The assignment operator.
It uses parameters and translator from the source tree.
\param src The rtree which content will be copied.
\par Throws
\li If Value copy constructor throws.
\li If allocation throws.
\li If allocation throws or returns invalid value.
*/
inline rtree & operator=(BOOST_COPY_ASSIGN_REF(rtree) src)
{
if ( &src != this )
{
allocators_type & this_allocs = m_members.allocators();
allocators_type const& src_allocs = src.m_members.allocators();
// NOTE: if propagate is true for std allocators on darwin 4.2.1, glibc++
// (allocators stored as base classes of members_holder)
// copying them changes values_count, in this case it doesn't cause errors since data must be copied
typedef std::integral_constant<bool,
allocator_traits_type::propagate_on_container_copy_assignment::value
> propagate;
if ( propagate::value && !(this_allocs == src_allocs) )
this->raw_destroy(*this);
detail::assign_cond(this_allocs, src_allocs, propagate());
// It uses m_allocators
this->raw_copy(src, *this, true);
}
return *this;
}
/*!
\brief The moving assignment.
It uses parameters and translator from the source tree.
\param src The rtree which content will be moved.
\par Throws
Only if allocators aren't equal.
\li If Value copy constructor throws.
\li If allocation throws or returns invalid value.
*/
inline rtree & operator=(BOOST_RV_REF(rtree) src)
{
if ( &src != this )
{
allocators_type & this_allocs = m_members.allocators();
allocators_type & src_allocs = src.m_members.allocators();
if ( this_allocs == src_allocs )
{
this->raw_destroy(*this);
m_members.indexable_getter() = src.m_members.indexable_getter();
m_members.equal_to() = src.m_members.equal_to();
m_members.parameters() = src.m_members.parameters();
boost::swap(m_members.values_count, src.m_members.values_count);
boost::swap(m_members.leafs_level, src.m_members.leafs_level);
boost::swap(m_members.root, src.m_members.root);
// NOTE: if propagate is true for std allocators on darwin 4.2.1, glibc++
// (allocators stored as base classes of members_holder)
// moving them changes values_count
typedef std::integral_constant<bool,
allocator_traits_type::propagate_on_container_move_assignment::value
> propagate;
detail::move_cond(this_allocs, src_allocs, propagate());
}
else
{
// TODO - shouldn't here propagate_on_container_copy_assignment be checked like in operator=(const&)?
// It uses m_allocators
this->raw_copy(src, *this, true);
}
}
return *this;
}
/*!
\brief Swaps contents of two rtrees.
Parameters, translator and allocators are swapped as well.
\param other The rtree which content will be swapped with this rtree content.
\par Throws
If allocators swap throws.
*/
void swap(rtree & other)
{
boost::swap(m_members.indexable_getter(), other.m_members.indexable_getter());
boost::swap(m_members.equal_to(), other.m_members.equal_to());
boost::swap(m_members.parameters(), other.m_members.parameters());
// NOTE: if propagate is true for std allocators on darwin 4.2.1, glibc++
// (allocators stored as base classes of members_holder)
// swapping them changes values_count
typedef std::integral_constant<bool,
allocator_traits_type::propagate_on_container_swap::value
> propagate;
detail::swap_cond(m_members.allocators(), other.m_members.allocators(), propagate());
boost::swap(m_members.values_count, other.m_members.values_count);
boost::swap(m_members.leafs_level, other.m_members.leafs_level);
boost::swap(m_members.root, other.m_members.root);
}
/*!
\brief Insert a value to the index.
\param value The value which will be stored in the container.
\par Throws
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
\warning
This operation only guarantees that there will be no memory leaks.
After an exception is thrown the R-tree may be left in an inconsistent state,
elements must not be inserted or removed. Other operations are allowed however
some of them may return invalid data.
*/
inline void insert(value_type const& value)
{
if ( !m_members.root )
this->raw_create();
this->raw_insert(value);
}
/*!
\brief Insert a range of values to the index.
\param first The beginning of the range of values.
\param last The end of the range of values.
\par Throws
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
\warning
This operation only guarantees that there will be no memory leaks.
After an exception is thrown the R-tree may be left in an inconsistent state,
elements must not be inserted or removed. Other operations are allowed however
some of them may return invalid data.
*/
template <typename Iterator>
inline void insert(Iterator first, Iterator last)
{
if ( !m_members.root )
this->raw_create();
for ( ; first != last ; ++first )
this->raw_insert(*first);
}
/*!
\brief Insert a value created using convertible object or a range of values to the index.
\param conv_or_rng An object of type convertible to value_type or a range of values.
\par Throws
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
\warning
This operation only guarantees that there will be no memory leaks.
After an exception is thrown the R-tree may be left in an inconsistent state,
elements must not be inserted or removed. Other operations are allowed however
some of them may return invalid data.
*/
template <typename ConvertibleOrRange>
inline void insert(ConvertibleOrRange const& conv_or_rng)
{
if ( !m_members.root )
this->raw_create();
typedef std::is_convertible<ConvertibleOrRange, value_type> is_conv_t;
typedef range::detail::is_range<ConvertibleOrRange> is_range_t;
BOOST_GEOMETRY_STATIC_ASSERT((is_conv_t::value || is_range_t::value),
"The argument has to be convertible to Value type or be a Range.",
ConvertibleOrRange);
this->insert_dispatch(conv_or_rng, is_conv_t());
}
/*!
\brief Remove a value from the container.
In contrast to the \c std::set or <tt>std::map erase()</tt> method
this method removes only one value from the container.
\param value The value which will be removed from the container.
\return 1 if the value was removed, 0 otherwise.
\par Throws
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
\warning
This operation only guarantees that there will be no memory leaks.
After an exception is thrown the R-tree may be left in an inconsistent state,
elements must not be inserted or removed. Other operations are allowed however
some of them may return invalid data.
*/
inline size_type remove(value_type const& value)
{
if ( !m_members.root )
return 0;
return this->raw_remove(value);
}
/*!
\brief Remove a range of values from the container.
In contrast to the \c std::set or <tt>std::map erase()</tt> method
it doesn't take iterators pointing to values stored in this container. It removes values equal
to these passed as a range. Furthermore this method removes only one value for each one passed
in the range, not all equal values.
\param first The beginning of the range of values.
\param last The end of the range of values.
\return The number of removed values.
\par Throws
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
\warning
This operation only guarantees that there will be no memory leaks.
After an exception is thrown the R-tree may be left in an inconsistent state,
elements must not be inserted or removed. Other operations are allowed however
some of them may return invalid data.
*/
template <typename Iterator>
inline size_type remove(Iterator first, Iterator last)
{
size_type result = 0;
if ( !m_members.root )
return result;
for ( ; first != last ; ++first )
result += this->raw_remove(*first);
return result;
}
/*!
\brief Remove value corresponding to an object convertible to it or a range of values from the container.
In contrast to the \c std::set or <tt>std::map erase()</tt> method
it removes values equal to these passed as a range. Furthermore, this method removes only
one value for each one passed in the range, not all equal values.
\param conv_or_rng The object of type convertible to value_type or a range of values.
\return The number of removed values.
\par Throws
\li If Value copy constructor or copy assignment throws.
\li If allocation throws or returns invalid value.
\warning
This operation only guarantees that there will be no memory leaks.
After an exception is thrown the R-tree may be left in an inconsistent state,
elements must not be inserted or removed. Other operations are allowed however
some of them may return invalid data.
*/
template <typename ConvertibleOrRange>
inline size_type remove(ConvertibleOrRange const& conv_or_rng)
{
if ( !m_members.root )
return 0;
typedef std::is_convertible<ConvertibleOrRange, value_type> is_conv_t;
typedef range::detail::is_range<ConvertibleOrRange> is_range_t;
BOOST_GEOMETRY_STATIC_ASSERT((is_conv_t::value || is_range_t::value),
"The argument has to be convertible to Value type or be a Range.",
ConvertibleOrRange);
return this->remove_dispatch(conv_or_rng, is_conv_t());
}
/*!
\brief Finds values meeting passed predicates e.g. nearest to some Point and/or intersecting some Box.
This query function performs spatial and k-nearest neighbor searches. It allows to pass a set of predicates.
Values will be returned only if all predicates are met.
<b>Spatial predicates</b>
Spatial predicates may be generated by one of the functions listed below:
\li \c boost::geometry::index::contains(),