Overpass API regression suite coverage (Nova Scotia) / overpass_api/core/index_computations.h

overpass_api/core/index_computations.h

619 of 1064 instrumented lines run by the suite (58.2%) at 8edf11b0419c (this file on GitHub).

runnever runcolumns: line, executions, queries (click for the queries that run the line)

1/** Copyright 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Roland Olbricht et al.
2 *
3 * This file is part of Overpass_API.
4 *
5 * Overpass_API is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * Overpass_API is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with Overpass_API. If not, see <http://www.gnu.org/licenses/>.
17 */
19#ifndef DE__OSM3S___OVERPASS_API__CORE__INDEX_COMPUTATIONS_H
20#define DE__OSM3S___OVERPASS_API__CORE__INDEX_COMPUTATIONS_H
22#include "../../template_db/ranges.h"
23#include "basic_types.h"
25#include <algorithm>
26#include <set>
27#include <vector>
30inline uint32 ll_upper(uint32 ilat, uint32 ilon);
31inline uint32 ll_upper_(uint32 ilat, int32 ilon);
32inline uint32 upper_ilat(uint32 quadtile);
33inline uint32 upper_ilon(uint32 quadtile);
34inline uint32 ilat(uint32 ll_upper, uint32 ll_lower);
35inline int32 ilon(uint32 ll_upper, uint32 ll_lower);
37inline uint32 calc_index(const std::vector< uint32 >& node_idxs);
38inline std::pair< Uint32_Index, Uint32_Index > calc_bbox_bounds(Uint31_Index way_rel_idx);
39inline std::vector< Uint32_Index > calc_node_children(const std::vector< uint32 >& way_rel_idxs);
40inline std::vector< Uint31_Index > calc_children(const std::vector< uint32 >& way_rel_idxs);
41inline std::vector< uint32 > calc_parents(const std::vector< uint32 >& node_idxs);
43inline Ranges< Uint32_Index > calc_ranges(double south, double north, double west, double east);
45inline void recursively_calc_ranges
46 (uint32 south, uint32 north, int32 west, int32 east,
47 uint32 bitlevel, Ranges< Uint32_Index >& ranges);
49/** ------------------------------------------------------------------------ */
51struct Uint31_Compare
53 bool operator()(uint32 a, uint32 b) const
5412593832108 q {
5512593832108 q return (a & 0x7fffffff) < (b & 0x7fffffff);
5612593832108 q }
57};
59inline uint32 ll_upper(uint32 ilat, uint32 ilon)
6020511671417 q{
6120511671417 q ilat &= 0xffff0000;
6220511671417 q ilat |= (ilat>>8);
6320511671417 q ilat &= 0xff00ff00;
6420511671417 q ilat |= (ilat>>4);
6520511671417 q ilat &= 0xf0f0f0f0;
6620511671417 q ilat |= (ilat>>2);
6720511671417 q ilat &= 0xcccccccc;
6820511671417 q ilat |= (ilat>>1);
6920511671417 q ilat &= 0xaaaaaaaa;
7120511671417 q ilon &= 0xffff0000;
7220511671417 q ilon |= (ilon>>8);
7320511671417 q ilon &= 0xff00ff00;
7420511671417 q ilon |= (ilon>>4);
7520511671417 q ilon &= 0xf0f0f0f0;
7620511671417 q ilon |= (ilon>>2);
7720511671417 q ilon &= 0xcccccccc;
7820511671417 q ilon |= (ilon>>1);
7920511671417 q ilon &= 0xaaaaaaaa;
8120511671417 q return ilat | (ilon>>1);
8220511671417 q}
84inline uint32 ll_upper_(uint32 ilat, int32 ilon)
852063797320 q{
862063797320 q return (ll_upper(ilat, ilon) ^ 0x40000000);
872063797320 q}
89inline uint32 upper_ilat(uint32 quadtile)
9014306562418 q{
9114306562418 q uint32 result = (quadtile & 0xaaaaaaaa)>>1;
9214306562418 q result |= (result>>1);
9314306562418 q result &= 0x33333333;
9414306562418 q result |= (result>>2);
9514306562418 q result &= 0x0f0f0f0f;
9614306562418 q result |= (result>>4);
9714306562418 q result &= 0x00ff00ff;
9814306562418 q result |= (result>>8);
10014306562418 q return result & 0xffff;
10114306562418 q}
103inline uint32 upper_ilon(uint32 quadtile)
10414306562418 q{
10514306562418 q uint32 result = (quadtile & 0x55555555);
10614306562418 q result |= (result>>1);
10714306562418 q result &= 0x33333333;
10814306562418 q result |= (result>>2);
10914306562418 q result &= 0x0f0f0f0f;
11014306562418 q result |= (result>>4);
11114306562418 q result &= 0x00ff00ff;
11214306562418 q result |= (result>>8);
11414306562418 q return result & 0xffff;
11514306562418 q}
117inline uint32 calc_index(const std::vector< uint32 >& node_idxs)
11822448963216 q{
11922448963216 q if (node_idxs.empty())
1200 return 0xfe;
122 // Calculate the bounding box of the appearing indices.
12422448963216 q std::vector< uint32 >::const_iterator it = node_idxs.begin();
12522448963216 q uint32 lat_min = *it & 0x2aaaaaaa;
12622448963216 q uint32 lat_max = lat_min;
12722448963216 q uint32 lon_min = *it & 0x55555555;
12822448963216 q uint32 lon_max = lon_min;
13022448963216 q if (*it & 0x80000000)
1310 {
1320 if (*it & 0x00000001)
1330 {
1340 lat_min = *it & 0x2aaaaaa8;
1350 lon_min = *it & 0x55555554;
1360 lat_max = ll_upper((upper_ilat(lat_min) + 3)<<16, 0);
1370 lon_max = ll_upper(0, (upper_ilon(lon_min) + 3)<<16);
1380 }
1390 else if (*it & 0x00000002)
1400 {
1410 lat_min = *it & 0x2aaaaa80;
1420 lon_min = *it & 0x55555540;
1430 lat_max = ll_upper((upper_ilat(lat_min) + 0xf)<<16, 0);
1440 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0xf)<<16);
1450 }
1460 else if (*it & 0x00000004)
1470 {
1480 lat_min = *it & 0x2aaaa800;
1490 lon_min = *it & 0x55555400;
1500 lat_max = ll_upper((upper_ilat(lat_min) + 0x3f)<<16, 0);
1510 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0x3f)<<16);
1520 }
1530 else if (*it & 0x00000008)
1540 {
1550 lat_min = *it & 0x2aaa8000;
1560 lon_min = *it & 0x55554000;
1570 lat_max = ll_upper((upper_ilat(lat_min) + 0xff)<<16, 0);
1580 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0xff)<<16);
1590 }
1600 else if (*it & 0x00000010)
1610 {
1620 lat_min = *it & 0x2aa80000;
1630 lon_min = *it & 0x55540000;
1640 lat_max = ll_upper((upper_ilat(lat_min) + 0x3ff)<<16, 0);
1650 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0x3ff)<<16);
1660 }
1670 else if (*it & 0x00000020)
1680 {
1690 lat_min = *it & 0x2a800000;
1700 lon_min = *it & 0x55400000;
1710 lat_max = ll_upper((upper_ilat(lat_min) + 0xfff)<<16, 0);
1720 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0xfff)<<16);
1730 }
1740 else if (*it & 0x00000040)
1750 {
1760 lat_min = *it & 0x28000000;
1770 lon_min = *it & 0x54000000;
1780 lat_max = ll_upper((upper_ilat(lat_min) + 0x3fff)<<16, 0);
1790 lon_max = ll_upper(0, (upper_ilon(lon_min) + 0x3fff)<<16);
1800 }
1810 else // *it == 0x80000080
1820 return 0x80000080;
1830 }
18544897952216 q for (++it; it != node_idxs.end(); ++it)
18622448989216 q {
18722448989216 q if (*it & 0x80000000)
1880 {
1890 uint32 lat = 0;
1900 uint32 lon = 0;
1910 uint32 lat_u = 0;
1920 uint32 lon_u = 0;
1940 if (*it & 0x00000001)
1950 {
1960 lat = *it & 0x2aaaaaa8;
1970 lon = *it & 0x55555554;
1980 lat_u = ll_upper((upper_ilat(lat) + 3)<<16, 0);
1990 lon_u = ll_upper(0, (upper_ilon(lon) + 3)<<16);
2000 }
2010 else if (*it & 0x00000002)
2020 {
2030 lat = *it & 0x2aaaaa80;
2040 lon = *it & 0x55555540;
2050 lat_u = ll_upper((upper_ilat(lat) + 0xf)<<16, 0);
2060 lon_u = ll_upper(0, (upper_ilon(lon) + 0xf)<<16);
2070 }
2080 else if (*it & 0x00000004)
2090 {
2100 lat = *it & 0x2aaaa800;
2110 lon = *it & 0x55555400;
2120 lat_u = ll_upper((upper_ilat(lat) + 0x3f)<<16, 0);
2130 lon_u = ll_upper(0, (upper_ilon(lon) + 0x3f)<<16);
2140 }
2150 else if (*it & 0x00000008)
2160 {
2170 lat = *it & 0x2aaa8000;
2180 lon = *it & 0x55554000;
2190 lat_u = ll_upper((upper_ilat(lat) + 0xff)<<16, 0);
2200 lon_u = ll_upper(0, (upper_ilon(lon) + 0xff)<<16);
2210 }
2220 else if (*it & 0x00000010)
2230 {
2240 lat = *it & 0x2aa80000;
2250 lon = *it & 0x55540000;
2260 lat_u = ll_upper((upper_ilat(lat) + 0x3ff)<<16, 0);
2270 lon_u = ll_upper(0, (upper_ilon(lon) + 0x3ff)<<16);
2280 }
2290 else if (*it & 0x00000020)
2300 {
2310 lat = *it & 0x2a800000;
2320 lon = *it & 0x55400000;
2330 lat_u = ll_upper((upper_ilat(lat) + 0xfff)<<16, 0);
2340 lon_u = ll_upper(0, (upper_ilon(lon) + 0xfff)<<16);
2350 }
2360 else if (*it & 0x00000040)
2370 {
2380 lat = *it & 0x28000000;
2390 lon = *it & 0x54000000;
2400 lat_u = ll_upper((upper_ilat(lat) + 0x3fff)<<16, 0);
2410 lon_u = ll_upper(0, (upper_ilon(lon) + 0x3fff)<<16);
2420 }
2430 else // *it == 0x80000080
2440 return 0x80000080;
2460 if (lat < lat_min)
2470 lat_min = lat;
2480 if (lat_u > lat_max)
2490 lat_max = lat_u;
2500 if (lon < lon_min)
2510 lon_min = lon;
2520 if (lon_u > lon_max)
2530 lon_max = lon_u;
2540 }
25522448989216 q else
25622448989216 q {
25722448989216 q uint32 lat = *it & 0x2aaaaaaa;
25822448989216 q uint32 lon = *it & 0x55555555;
26022448989216 q if (lat < lat_min)
2611836629215 q lat_min = lat;
26220612360216 q else if (lat > lat_max)
2631890287216 q lat_max = lat;
26422448989216 q if (lon < lon_min)
2652090080216 q lon_min = lon;
26620358909216 q else if (lon > lon_max)
2672468822215 q lon_max = lon;
26822448989216 q }
26922448989216 q }
272 // Evaluate the bounding box.
27422448963216 q if ((lat_max == lat_min) && (lon_max == lon_min))
27516940680215 q return node_idxs.front();
2775508283216 q uint32 ilat_min = upper_ilat(lat_min);
2785508283216 q uint32 ilat_max = upper_ilat(lat_max);
2795508283216 q uint32 ilon_min = upper_ilon(lon_min);
2805508283216 q uint32 ilon_max = upper_ilon(lon_max);
2825508283216 q if (((ilat_max & 0xfffe) - (ilat_min & 0xfffe) < 4) &&
2835508283216 q ((ilon_max & 0xfffe) - (ilon_min & 0xfffe) < 4))
2843090540214 q return (((lon_min | lat_min) & 0xfffffffc) | 0x80000001);
2862417743214 q if (((ilat_max & 0xfff8) - (ilat_min & 0xfff8) < 0x10) &&
2872417743214 q ((ilon_max & 0xfff8) - (ilon_min & 0xfff8) < 0x10))
288155301212 q return (((lon_min | lat_min) & 0xffffffc0) | 0x80000002);
2902262442211 q if (((ilat_max & 0xffe0) - (ilat_min & 0xffe0) < 0x40) &&
2912262442211 q ((ilon_max & 0xffe0) - (ilon_min & 0xffe0) < 0x40))
29233523211 q return (((lon_min | lat_min) & 0xfffffc00) | 0x80000004);
2942228919164 q if (((ilat_max & 0xff80) - (ilat_min & 0xff80) < 0x100) &&
2952228919164 q ((ilon_max & 0xff80) - (ilon_min & 0xff80) < 0x100))
2967536164 q return (((lon_min | lat_min) & 0xffffc000) | 0x80000008);
2982221383148 q if (((ilat_max & 0xfe00) - (ilat_min & 0xfe00) < 0x400) &&
2992221383148 q ((ilon_max & 0xfe00) - (ilon_min & 0xfe00) < 0x400))
30044402148 q return (((lon_min | lat_min) & 0xfffc0000) | 0x80000010);
302217698185 q if (((ilat_max & 0xf800) - (ilat_min & 0xf800) < 0x1000) &&
303217698185 q ((ilon_max & 0xf800) - (ilon_min & 0xf800) < 0x1000))
30425833685 q return (((lon_min | lat_min) & 0xffc00000) | 0x80000020);
306191864585 q if (((ilat_max & 0xe000) - (ilat_min & 0xe000) < 0x4000) &&
307191864585 q ((ilon_max & 0xe000) - (ilon_min & 0xe000) < 0x4000))
30884651985 q return (((lon_min | lat_min) & 0xfc000000) | 0x80000040);
310107212685 q return 0x80000080;
311191864585 q}
314inline std::pair< Uint32_Index, Uint32_Index > calc_bbox_bounds(Uint31_Index way_rel_idx)
3150{
3160 if (way_rel_idx.val() & 0x80000000)
3170 {
3180 uint32 lat = 0;
3190 uint32 lon = 0;
3200 uint32 offset = 0;
3220 if (way_rel_idx.val() & 0x00000001)
3230 {
3240 lat = upper_ilat(way_rel_idx.val() & 0x2aaaaaa8);
3250 lon = upper_ilon(way_rel_idx.val() & 0x55555554);
3260 offset = 2;
3270 }
3280 else if (way_rel_idx.val() & 0x00000002)
3290 {
3300 lat = upper_ilat(way_rel_idx.val() & 0x2aaaaa80);
3310 lon = upper_ilon(way_rel_idx.val() & 0x55555540);
3320 offset = 8;
3330 }
3340 else if (way_rel_idx.val() & 0x00000004)
3350 {
3360 lat = upper_ilat(way_rel_idx.val() & 0x2aaaa800);
3370 lon = upper_ilon(way_rel_idx.val() & 0x55555400);
3380 offset = 0x20;
3390 }
3400 else if (way_rel_idx.val() & 0x00000008)
3410 {
3420 lat = upper_ilat(way_rel_idx.val() & 0x2aaa8000);
3430 lon = upper_ilon(way_rel_idx.val() & 0x55554000);
3440 offset = 0x80;
3450 }
3460 else if (way_rel_idx.val() & 0x00000010)
3470 {
3480 lat = upper_ilat(way_rel_idx.val() & 0x2aa80000);
3490 lon = upper_ilon(way_rel_idx.val() & 0x55540000);
3500 offset = 0x200;
3510 }
3520 else if (way_rel_idx.val() & 0x00000020)
3530 {
3540 lat = upper_ilat(way_rel_idx.val() & 0x2a800000);
3550 lon = upper_ilon(way_rel_idx.val() & 0x55400000);
3560 offset = 0x800;
3570 }
3580 else if (way_rel_idx.val() & 0x00000040)
3590 {
3600 lat = upper_ilat(way_rel_idx.val() & 0x28000000);
3610 lon = upper_ilon(way_rel_idx.val() & 0x54000000);
3620 offset = 0x2000;
3630 }
3640 else // way_rel_idx.val() == 0x80000080
3650 {
3660 lat = 0;
3670 lon = 0;
3680 offset = 0x8000;
3690 }
3710 return std::make_pair(ll_upper(lat<<16, lon<<16),
3720 ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1);
3730 }
3740 else if (way_rel_idx.val() > 0xff)
3750 return std::make_pair(way_rel_idx.val(), way_rel_idx.val() + 1);
3760 else
3770 return std::make_pair(0u, 1u);
3780}
381inline std::vector< Uint32_Index > calc_node_children(const std::vector< uint32 >& way_rel_idxs)
3820{
3830 std::vector< Uint32_Index > result;
3850 std::vector< std::pair< uint32, uint32 > > ranges;
3870 for (std::vector< uint32 >::const_iterator it = way_rel_idxs.begin();
3880 it != way_rel_idxs.end(); ++it)
3890 {
3900 if (*it & 0x80000000)
3910 {
3920 uint32 lat = 0;
3930 uint32 lon = 0;
3940 uint32 lat_u = 0;
3950 uint32 lon_u = 0;
3960 uint32 offset = 0;
3980 if (*it & 0x00000001)
3990 {
4000 lat = upper_ilat(*it & 0x2aaaaaa8);
4010 lon = upper_ilon(*it & 0x55555554);
4020 offset = 2;
4030 }
4040 else if (*it & 0x00000002)
4050 {
4060 lat = upper_ilat(*it & 0x2aaaaa80);
4070 lon = upper_ilon(*it & 0x55555540);
4080 offset = 8;
4090 }
4100 else if (*it & 0x00000004)
4110 {
4120 lat = upper_ilat(*it & 0x2aaaa800);
4130 lon = upper_ilon(*it & 0x55555400);
4140 offset = 0x20;
4150 }
4160 else if (*it & 0x00000008)
4170 {
4180 lat = upper_ilat(*it & 0x2aaa8000);
4190 lon = upper_ilon(*it & 0x55554000);
4200 offset = 0x80;
4210 }
4220 else if (*it & 0x00000010)
4230 {
4240 lat = upper_ilat(*it & 0x2aa80000);
4250 lon = upper_ilon(*it & 0x55540000);
4260 offset = 0x200;
4270 }
4280 else if (*it & 0x00000020)
4290 {
4300 lat = upper_ilat(*it & 0x2a800000);
4310 lon = upper_ilon(*it & 0x55400000);
4320 offset = 0x800;
4330 }
4340 else if (*it & 0x00000040)
4350 {
4360 lat = upper_ilat(*it & 0x28000000);
4370 lon = upper_ilon(*it & 0x54000000);
4380 offset = 0x2000;
4390 }
4400 else // *it == 0x80000080
4410 {
4420 lat = 0;
4430 lon = 0;
4440 offset = 0x8000;
4450 }
4470 ranges.push_back(std::make_pair(ll_upper(lat<<16, lon<<16),
4480 ll_upper((lat+offset-1)<<16, (lon+offset-1)<<16)+1));
4490 ranges.push_back(std::make_pair(ll_upper(lat<<16, (lon+offset)<<16),
4500 ll_upper((lat+offset-1)<<16, (lon+2*offset-1)<<16)+1));
4510 ranges.push_back(std::make_pair(ll_upper((lat+offset)<<16, lon<<16),
4520 ll_upper((lat+2*offset-1)<<16, (lon+offset-1)<<16)+1));
4530 ranges.push_back(std::make_pair(ll_upper((lat+offset)<<16, (lon+offset)<<16),
4540 ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1));
4550 for (uint32 i = lat; i <= lat_u; ++i)
4560 {
4570 for (uint32 j = lon; j <= lon_u; ++j)
4580 result.push_back(ll_upper(i<<16, j<<16));
4590 }
4600 }
4610 else
4620 ranges.push_back(std::make_pair(*it, (*it) + 1));
4630 }
4650 sort(ranges.begin(), ranges.end());
4660 uint32 pos = 0;
4670 for (std::vector< std::pair< uint32, uint32 > >::const_iterator it = ranges.begin();
4680 it != ranges.end(); ++it)
4690 {
4700 if (pos < it->first)
4710 pos = it->first;
4720 for (; pos < it->second; ++pos)
4730 result.push_back(pos);
4740 }
4750 return result;
4760}
479struct Idx_Bbox
481 Idx_Bbox(uint32 ll_upper)
482152972172 q {
483152972172 q if (ll_upper & 0x80000000)
484120357168 q {
485120357168 q if (ll_upper & 0x00000001)
48667336136 q {
48767336136 q lat = upper_ilat(ll_upper & 0x2aaaaaa8);
48867336136 q lon = upper_ilon(ll_upper & 0x55555554);
48967336136 q lat_u = lat + 3;
49067336136 q lon_u = lon + 3;
49167336136 q }
49253021162 q else if (ll_upper & 0x00000002)
49353021162 q {
49453021162 q lat = upper_ilat(ll_upper & 0x2aaaaa80);
49553021162 q lon = upper_ilon(ll_upper & 0x55555540);
49653021162 q lat_u = lat + 0xf;
49753021162 q lon_u = lon + 0xf;
49853021162 q }
4990 else if (ll_upper & 0x00000004)
5000 {
5010 lat = upper_ilat(ll_upper & 0x2aaaa800);
5020 lon = upper_ilon(ll_upper & 0x55555400);
5030 lat_u = lat + 0x3f;
5040 lon_u = lon + 0x3f;
5050 }
5060 else if (ll_upper & 0x00000008)
5070 {
5080 lat = upper_ilat(ll_upper & 0x2aaa8000);
5090 lon = upper_ilon(ll_upper & 0x55554000);
5100 lat_u = lat + 0xff;
5110 lon_u = lon + 0xff;
5120 }
5130 else if (ll_upper & 0x00000010)
5140 {
5150 lat = upper_ilat(ll_upper & 0x2aa80000);
5160 lon = upper_ilon(ll_upper & 0x55540000);
5170 lat_u = lat + 0x3ff;
5180 lon_u = lon + 0x3ff;
5190 }
5200 else if (ll_upper & 0x00000020)
5210 {
5220 lat = upper_ilat(ll_upper & 0x2a800000);
5230 lon = upper_ilon(ll_upper & 0x55400000);
5240 lat_u = lat + 0xfff;
5250 lon_u = lon + 0xfff;
5260 }
5270 else if (ll_upper & 0x00000040)
5280 {
5290 lat = upper_ilat(ll_upper & 0x28000000);
5300 lon = upper_ilon(ll_upper & 0x54000000);
5310 lat_u = lat + 0x3fff;
5320 lon_u = lon + 0x3fff;
5330 }
5340 else // ll_upper == 0x80000080
5350 {
5360 lat = 0;
5370 lon = 0;
5380 lat_u = 0x7fff;
5390 lon_u = 0xffff;
5400 }
541120357168 q }
54232615102 q else
54332615102 q {
54432615102 q lat = upper_ilat(ll_upper);
54532615102 q lon = upper_ilon(ll_upper);
54632615102 q lat_u = lat;
54732615102 q lon_u = lon;
54832615102 q }
549152972172 q }
551 int compare(const Idx_Bbox& rhs)
552117117158 q {
553117117158 q bool lhs_bigger = (lat < rhs.lat || lon < rhs.lon || lat_u > rhs.lat_u || lon_u > rhs.lon_u);
554117117158 q bool rhs_bigger = (lat > rhs.lat || lon > rhs.lon || lat_u < rhs.lat_u || lon_u < rhs.lon_u);
555117117158 q return (lhs_bigger<<1) | rhs_bigger;
556117117158 q }
558 int32 lat;
559 int32 lon;
560 int32 lat_u;
561 int32 lon_u;
562};
565inline std::vector< Uint31_Index > calc_children(const std::vector< uint32 >& way_rel_idxs)
5660{
5670 std::vector< Uint31_Index > result;
5690 for (std::vector< uint32 >::const_iterator it = way_rel_idxs.begin();
5700 it != way_rel_idxs.end(); ++it)
5710 {
5720 if (*it & 0x80000000)
5730 {
5740 Idx_Bbox bbox(*it);
5760 if (!(*it & 0x0000007f))
5770 result.push_back(0x80000080);
5780 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3fff); i += 0x2000)
5790 {
5800 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3fff); j += 0x2000)
5810 result.push_back((ll_upper(i<<16, j<<16) & 0xfc000000) | 0x80000040);
5820 }
5830 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xfff); i += 0x800)
5840 {
5850 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xfff); j += 0x800)
5860 result.push_back((ll_upper(i<<16, j<<16) & 0xffc00000) | 0x80000020);
5870 }
5880 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3ff); i += 0x200)
5890 {
5900 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3ff); j += 0x200)
5910 result.push_back((ll_upper(i<<16, j<<16) & 0xfffc0000) | 0x80000010);
5920 }
5930 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xff); i += 0x80)
5940 {
5950 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xff); j += 0x80)
5960 result.push_back((ll_upper(i<<16, j<<16) & 0xffffc000) | 0x80000008);
5970 }
5980 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3f); i += 0x20)
5990 {
6000 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3f); j += 0x20)
6010 result.push_back((ll_upper(i<<16, j<<16) & 0xfffffc00) | 0x80000004);
6020 }
6030 for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xf); i += 8)
6040 {
6050 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xf); j += 8)
6060 result.push_back((ll_upper(i<<16, j<<16) & 0xffffffc0) | 0x80000002);
6070 }
6080 for (int32 i = bbox.lat; i <= (bbox.lat_u - 3); i += 2)
6090 {
6100 for (int32 j = bbox.lon; j <= (bbox.lon_u - 3); j += 2)
6110 result.push_back((ll_upper(i<<16, j<<16) & 0xfffffffc) | 0x80000001);
6120 }
6130 for (int32 i = bbox.lat; i <= bbox.lat_u; ++i)
6140 {
6150 for (int32 j = bbox.lon; j <= bbox.lon_u; ++j)
6160 result.push_back(ll_upper(i<<16, j<<16));
6170 }
6180 }
6190 else
6200 result.push_back(*it);
6210 }
6230 sort(result.begin(), result.end());
6240 result.erase(unique(result.begin(), result.end()), result.end());
6250 return result;
6260}
629inline Ranges< Uint31_Index > calc_children(std::vector< Uint31_Index >&& parents)
6314709420 q Ranges< Uint31_Index > result;
6334709420 q if (parents.empty())
6343575307 q return result;
6351134172 q std::sort(parents.begin(), parents.end());
6361134172 q auto i_src = parents.begin()+1;
6371134172 q auto i_target = parents.begin();
6381134172 q Idx_Bbox bbox_target(i_target->val());
639118251172 q while (i_src != parents.end())
640117117158 q {
641117117158 q Idx_Bbox bbox_src(i_src->val());
642117117158 q uint comp = bbox_target.compare(bbox_src);
643117117158 q if (comp == 3)
64435450156 q ++i_target;
645117117158 q if (comp == 1 || comp == 3)
64637303156 q {
64737303156 q *i_target = *i_src;
64837303156 q bbox_target = bbox_src;
64937303156 q }
650117117158 q ++i_src;
651117117158 q }
6521134172 q parents.erase(i_target+1, parents.end());
6541134172 q for (auto i : parents)
65536584172 q {
65636584172 q if (i.val() & 0x80000000)
65734721168 q {
65834721168 q Idx_Bbox bbox(i.val());
66034721168 q if (!(i.val() & 0x0000007f))
6610 result.push_back(0x80000080, 0x81);
66234721168 q for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3fff); i += 0x2000)
6630 {
6640 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3fff); j += 0x2000)
6650 {
6660 Uint31_Index idx((ll_upper(i<<16, j<<16) & 0xfc000000) | 0x80000040);
6670 result.push_back(idx, inc(idx));
6680 }
6690 }
67034721168 q for (int32 i = bbox.lat; i <= (bbox.lat_u - 0xfff); i += 0x800)
6710 {
6720 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0xfff); j += 0x800)
6730 {
6740 Uint31_Index idx((ll_upper(i<<16, j<<16) & 0xffc00000) | 0x80000020);
6750 result.push_back(idx, inc(idx));
6760 }
6770 }
67834721168 q for (int32 i = bbox.lat; i <= (bbox.lat_u - 0x3ff); i += 0x200)
6790 {
6800 for (int32 j = bbox.lon; j <= (bbox.lon_u - 0x3ff); j += 0x200)
6810 {
6820 Uint31_Index idx((ll_upper(i<<16, j<<16) & 0xfffc0000) | 0x80000010);
6830 result.push_back(idx, inc(idx));
6840 }
6850 }
686263199168 q for (int32 i = bbox.lat; i <= bbox.lat_u; i += 2)
687228478168 q {
6881957722168 q for (int32 j = bbox.lon; j <= bbox.lon_u; j += 2)
6891729244168 q {
6901729244168 q uint32 idx = ll_upper(i<<16, j<<16);
6911729244168 q uint32 lower = idx;
6921729244168 q if (((idx & 0xf) == 0x0 && ((idx & 0x3ffff) == 0x10 || (idx & 0x3fffff) == 0x20
693432311168 q || (idx & 0x3ffffff) == 0x40 || (idx & 0x3fffffff) == 0x80))
6941729244168 q || ((idx & 0x3ff) == 0x4 && (i > (bbox.lat_u - 0x3f) || j > (bbox.lon_u - 0x3d)))
6951729244168 q || ((idx & 0x3fff) == 0x8 && (i > (bbox.lat_u - 0xfd) || j > (bbox.lon_u - 0xff))))
6967407121 q {
6977407121 q result.push_back(Uint31_Index(idx), Uint31_Index(idx | 0x80000000));
6987407121 q lower = idx+1;
6997407121 q }
7001729244168 q if (i > (bbox.lat_u - 3) || j > (bbox.lon_u - 3))
701422235168 q {
702422235168 q result.push_back(Uint31_Index(lower), Uint31_Index((idx+1) | 0x80000000));
703422235168 q lower = idx+2;
704422235168 q }
7051729244168 q if ((idx & 0x3f) == 0x2 && (i > (bbox.lat_u - 0xf) || j > (bbox.lon_u - 0xf)))
7060 {
7070 result.push_back(Uint31_Index(lower), Uint31_Index((idx+2) | 0x80000000));
7080 lower = idx+3;
7090 }
7101729244168 q result.push_back(Uint31_Index(lower), Uint31_Index(idx+4));
7111729244168 q }
712228478168 q }
71334721168 q }
714186345 q else
715186345 q result.push_back(i, inc(i));
71636584172 q }
7181134172 q result.sort();
7191134172 q return result;
723inline Ranges< Uint31_Index > calc_children_(const std::vector< Uint31_Index >& parents)
7254709420 q auto copy = parents;
7264709420 q return calc_children(std::move(copy));
730inline Ranges< Uint32_Index > calc_children(const Ranges< Uint31_Index >& way_rel_idxs)
73216632 q Ranges< Uint32_Index > ranges;
7348098232 q for (auto it = way_rel_idxs.begin(); it != way_rel_idxs.end(); ++it)
7358081618 q {
73617049018 q for (Uint31_Index idx = it.lower_bound(); idx < it.upper_bound(); idx = inc(idx))
7378967418 q {
7388967418 q if (idx.val() & 0x80000000)
7396639515 q {
7406639515 q uint32 lat = 0;
7416639515 q uint32 lon = 0;
7426639515 q uint32 offset = 0;
7446639515 q if (idx.val() & 0x00000001)
7454411713 q {
7464411713 q lat = upper_ilat(idx.val() & 0x2aaaaaa8);
7474411713 q lon = upper_ilon(idx.val() & 0x55555554);
7484411713 q offset = 2;
7494411713 q }
7502227811 q else if (idx.val() & 0x00000002)
751191269 q {
752191269 q lat = upper_ilat(idx.val() & 0x2aaaaa80);
753191269 q lon = upper_ilon(idx.val() & 0x55555540);
754191269 q offset = 8;
755191269 q }
756315210 q else if (idx.val() & 0x00000004)
75725049 q {
75825049 q lat = upper_ilat(idx.val() & 0x2aaaa800);
75925049 q lon = upper_ilon(idx.val() & 0x55555400);
76025049 q offset = 0x20;
76125049 q }
7626487 q else if (idx.val() & 0x00000008)
7633676 q {
7643676 q lat = upper_ilat(idx.val() & 0x2aaa8000);
7653676 q lon = upper_ilon(idx.val() & 0x55554000);
7663676 q offset = 0x80;
7673676 q }
7682815 q else if (idx.val() & 0x00000010)
769935 q {
770935 q lat = upper_ilat(idx.val() & 0x2aa80000);
771935 q lon = upper_ilon(idx.val() & 0x55540000);
772935 q offset = 0x200;
773935 q }
7741882 q else if (idx.val() & 0x00000020)
775882 q {
776882 q lat = upper_ilat(idx.val() & 0x2a800000);
777882 q lon = upper_ilon(idx.val() & 0x55400000);
778882 q offset = 0x800;
779882 q }
7801001 q else if (idx.val() & 0x00000040)
781901 q {
782901 q lat = upper_ilat(idx.val() & 0x28000000);
783901 q lon = upper_ilon(idx.val() & 0x54000000);
784901 q offset = 0x2000;
785901 q }
786101 q else // idx.val() == 0x80000080
787101 q {
788101 q lat = 0;
789101 q lon = 0;
790101 q offset = 0x8000;
791101 q }
7936639515 q ranges.push_back(
7946639515 q ll_upper(lat<<16, lon<<16),
7956639515 q ll_upper((lat+offset-1)<<16, (lon+offset-1)<<16)+1);
7966639515 q ranges.push_back(
7976639515 q ll_upper(lat<<16, (lon+offset)<<16),
7986639515 q ll_upper((lat+offset-1)<<16, (lon+2*offset-1)<<16)+1);
7996639515 q ranges.push_back(
8006639515 q ll_upper((lat+offset)<<16, lon<<16),
8016639515 q ll_upper((lat+2*offset-1)<<16, (lon+offset-1)<<16)+1);
8026639515 q ranges.push_back(
8036639515 q ll_upper((lat+offset)<<16, (lon+offset)<<16),
8046639515 q ll_upper((lat+2*offset-1)<<16, (lon+2*offset-1)<<16)+1);
8056639515 q }
8062327911 q else
8072327911 q ranges.push_back(idx.val(), idx.val() + 1);
8088967418 q }
8098081618 q }
81016632 q ranges.sort();
81216632 q return ranges;
816inline std::set< Uint31_Index > calc_parents(const std::set< Uint31_Index >& node_idxs)
8184341 q std::set< Uint31_Index > result;
8194341 q result.insert(0x80000080);
8214341 q for (std::set< Uint31_Index >::const_iterator it = node_idxs.begin();
822759341 q it != node_idxs.end(); ++it)
823755036 q {
824755036 q result.insert(*it);
826755036 q uint32 lat = upper_ilat(it->val() & 0x2aaaaaa8) & 0xfffe;
827755036 q uint32 lon = upper_ilon(it->val() & 0x55555554) & 0xfffe;
828755036 q result.insert(ll_upper((lat - 2)<<16, (lon - 2)<<16) | 0x80000001);
829755036 q result.insert(ll_upper(lat<<16, (lon - 2)<<16) | 0x80000001);
830755036 q result.insert(ll_upper((lat - 2)<<16, lon<<16) | 0x80000001);
831755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000001);
833755036 q lat = lat & 0xfff8;
834755036 q lon = lon & 0xfff8;
835755036 q result.insert(ll_upper((lat - 8)<<16, (lon - 8)<<16) | 0x80000002);
836755036 q result.insert(ll_upper(lat<<16, (lon - 8)<<16) | 0x80000002);
837755036 q result.insert(ll_upper((lat - 8)<<16, lon<<16) | 0x80000002);
838755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000002);
840755036 q lat = lat & 0xffe0;
841755036 q lon = lon & 0xffe0;
842755036 q result.insert(ll_upper((lat - 0x20)<<16, (lon - 0x20)<<16) | 0x80000004);
843755036 q result.insert(ll_upper(lat<<16, (lon - 0x20)<<16) | 0x80000004);
844755036 q result.insert(ll_upper((lat - 0x20)<<16, lon<<16) | 0x80000004);
845755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000004);
847755036 q lat = lat & 0xff80;
848755036 q lon = lon & 0xff80;
849755036 q result.insert(ll_upper((lat - 0x80)<<16, (lon - 0x80)<<16) | 0x80000008);
850755036 q result.insert(ll_upper(lat<<16, (lon - 0x80)<<16) | 0x80000008);
851755036 q result.insert(ll_upper((lat - 0x80)<<16, lon<<16) | 0x80000008);
852755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000008);
854755036 q lat = lat & 0xfe00;
855755036 q lon = lon & 0xfe00;
856755036 q result.insert(ll_upper((lat - 0x200)<<16, (lon - 0x200)<<16) | 0x80000010);
857755036 q result.insert(ll_upper(lat<<16, (lon - 0x200)<<16) | 0x80000010);
858755036 q result.insert(ll_upper((lat - 0x200)<<16, lon<<16) | 0x80000010);
859755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000010);
861755036 q lat = lat & 0xf800;
862755036 q lon = lon & 0xf800;
863755036 q result.insert(ll_upper((lat - 0x800)<<16, (lon - 0x800)<<16) | 0x80000020);
864755036 q result.insert(ll_upper(lat<<16, (lon - 0x800)<<16) | 0x80000020);
865755036 q result.insert(ll_upper((lat - 0x800)<<16, lon<<16) | 0x80000020);
866755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000020);
868755036 q lat = lat & 0xe000;
869755036 q lon = lon & 0xe000;
870755036 q result.insert(ll_upper((lat - 0x2000)<<16, (lon - 0x2000)<<16) | 0x80000040);
871755036 q result.insert(ll_upper(lat<<16, (lon - 0x2000)<<16) | 0x80000040);
872755036 q result.insert(ll_upper((lat - 0x2000)<<16, lon<<16) | 0x80000040);
873755036 q result.insert(ll_upper(lat<<16, lon<<16) | 0x80000040);
874755036 q }
8764341 q return result;
880inline std::vector< uint32 > calc_parents(const std::vector< uint32 >& node_idxs)
882550143 q std::vector< uint32 > result;
883550143 q result.push_back(0x80000080);
885550143 q for (std::vector< uint32 >::const_iterator it = node_idxs.begin();
88629237143 q it != node_idxs.end(); ++it)
88728687108 q {
88828687108 q result.push_back(*it);
89028687108 q uint32 lat = upper_ilat(*it & 0x2aaaaaa8) & 0xfffe;
89128687108 q uint32 lon = upper_ilon(*it & 0x55555554) & 0xfffe;
89228687108 q result.push_back(ll_upper((lat - 2)<<16, (lon - 2)<<16) | 0x80000001);
89328687108 q result.push_back(ll_upper(lat<<16, (lon - 2)<<16) | 0x80000001);
89428687108 q result.push_back(ll_upper((lat - 2)<<16, lon<<16) | 0x80000001);
89528687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000001);
89728687108 q lat = lat & 0xfff8;
89828687108 q lon = lon & 0xfff8;
89928687108 q result.push_back(ll_upper((lat - 8)<<16, (lon - 8)<<16) | 0x80000002);
90028687108 q result.push_back(ll_upper(lat<<16, (lon - 8)<<16) | 0x80000002);
90128687108 q result.push_back(ll_upper((lat - 8)<<16, lon<<16) | 0x80000002);
90228687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000002);
90428687108 q lat = lat & 0xffe0;
90528687108 q lon = lon & 0xffe0;
90628687108 q result.push_back(ll_upper((lat - 0x20)<<16, (lon - 0x20)<<16) | 0x80000004);
90728687108 q result.push_back(ll_upper(lat<<16, (lon - 0x20)<<16) | 0x80000004);
90828687108 q result.push_back(ll_upper((lat - 0x20)<<16, lon<<16) | 0x80000004);
90928687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000004);
91128687108 q lat = lat & 0xff80;
91228687108 q lon = lon & 0xff80;
91328687108 q result.push_back(ll_upper((lat - 0x80)<<16, (lon - 0x80)<<16) | 0x80000008);
91428687108 q result.push_back(ll_upper(lat<<16, (lon - 0x80)<<16) | 0x80000008);
91528687108 q result.push_back(ll_upper((lat - 0x80)<<16, lon<<16) | 0x80000008);
91628687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000008);
91828687108 q lat = lat & 0xfe00;
91928687108 q lon = lon & 0xfe00;
92028687108 q result.push_back(ll_upper((lat - 0x200)<<16, (lon - 0x200)<<16) | 0x80000010);
92128687108 q result.push_back(ll_upper(lat<<16, (lon - 0x200)<<16) | 0x80000010);
92228687108 q result.push_back(ll_upper((lat - 0x200)<<16, lon<<16) | 0x80000010);
92328687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000010);
92528687108 q lat = lat & 0xf800;
92628687108 q lon = lon & 0xf800;
92728687108 q result.push_back(ll_upper((lat - 0x800)<<16, (lon - 0x800)<<16) | 0x80000020);
92828687108 q result.push_back(ll_upper(lat<<16, (lon - 0x800)<<16) | 0x80000020);
92928687108 q result.push_back(ll_upper((lat - 0x800)<<16, lon<<16) | 0x80000020);
93028687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000020);
93228687108 q lat = lat & 0xe000;
93328687108 q lon = lon & 0xe000;
93428687108 q result.push_back(ll_upper((lat - 0x2000)<<16, (lon - 0x2000)<<16) | 0x80000040);
93528687108 q result.push_back(ll_upper(lat<<16, (lon - 0x2000)<<16) | 0x80000040);
93628687108 q result.push_back(ll_upper((lat - 0x2000)<<16, lon<<16) | 0x80000040);
93728687108 q result.push_back(ll_upper(lat<<16, lon<<16) | 0x80000040);
93828687108 q }
940550143 q sort(result.begin(), result.end(), Uint31_Compare());
941550143 q result.erase(unique(result.begin(), result.end()), result.end());
943550143 q return result;
947inline void push_back_interval(Ranges< Uint31_Index >& ranges, uint32 idx)
9486941530346 q{
9496941530346 q ranges.push_back(Uint31_Index(idx), Uint31_Index((idx + 1) & 0x7fffffff));
9506941530346 q}
953inline void blur_index(
954 uint32 distance, uint32 bitmask, uint32 lower_idx, uint32 upper_idx, Ranges< Uint31_Index >& result)
9551349782346 q{
9561349782346 q uint32 source_bitmask = 0x10000 - distance;
9571349782346 q uint32 min_lat = upper_ilat(lower_idx) & source_bitmask;
9581349782346 q uint32 min_lon = upper_ilon(lower_idx) & source_bitmask;
9591349782346 q uint32 max_lat = upper_ilat(upper_idx) & source_bitmask;
9601349782346 q uint32 max_lon = upper_ilon(upper_idx) & source_bitmask;
9614754931346 q for (uint32 lat = min_lat - distance; lat <= max_lat; lat += distance)
9623405149346 q push_back_interval(result, ll_upper(lat<<16, (min_lon - distance)<<16) | bitmask);
9633536381346 q for (uint32 lon = min_lon; lon <= max_lon; lon += distance)
9642186599346 q push_back_interval(result, ll_upper((min_lat - distance)<<16, lon<<16) | bitmask);
9651349782346 q push_back_interval(result, ll_upper(max_lat<<16, max_lon<<16) | bitmask);
9661349782346 q}
969inline void add_decomp_range(const std::pair< Uint32_Index, Uint32_Index >& range,
970 std::vector< std::pair< Uint32_Index, Uint32_Index > >& node_decomp)
971137040346 q{
972137040346 q uint32 lower = range.first.val();
973329866346 q while (lower < range.second.val())
974192826346 q {
975192826346 q uint32 upper = 0;
976192826346 q if ((lower & 0x3) != 0 || lower + 4 > range.second.val())
977152040259 q upper = lower + 1;
97840786327 q else if ((lower & 0xf) != 0 || lower + 0x10 > range.second.val())
97918032246 q upper = lower + 4;
98022754208 q else if ((lower & 0x3f) != 0 || lower + 0x40 > range.second.val())
9812693121 q upper = lower + 0x10;
98220061152 q else if ((lower & 0xff) != 0 || lower + 0x100 > range.second.val())
983154054 q upper = lower + 0x40;
98418521129 q else if ((lower & 0x3ff) != 0 || lower + 0x400 > range.second.val())
98512320119 q upper = lower + 0x100;
986620132 q else if ((lower & 0xfff) != 0 || lower + 0x1000 > range.second.val())
987420126 q upper = lower + 0x400;
988200027 q else if ((lower & 0x3fff) != 0 || lower + 0x4000 > range.second.val())
989136219 q upper = lower + 0x1000;
99063824 q else if ((lower & 0xffff) != 0 || lower + 0x10000 > range.second.val())
99144219 q upper = lower + 0x4000;
9921969 q else if ((lower & 0x3ffff) != 0 || lower + 0x40000 > range.second.val())
993302 q upper = lower + 0x10000;
9941667 q else if ((lower & 0xfffff) != 0 || lower + 0x100000 > range.second.val())
995565 q upper = lower + 0x40000;
9961102 q else if ((lower & 0x3fffff) != 0 || lower + 0x400000 > range.second.val())
9970 upper = lower + 0x100000;
9981102 q else if ((lower & 0xffffff) != 0 || lower + 0x1000000 > range.second.val())
999141 q upper = lower + 0x400000;
1000961 q else if ((lower & 0x3ffffff) != 0 || lower + 0x4000000 > range.second.val())
10010 upper = lower + 0x1000000;
1002961 q else if ((lower & 0xfffffff) != 0 || lower + 0x10000000 > range.second.val())
1003961 q upper = lower + 0x4000000;
10040 else if ((lower & 0x3fffffff) != 0 || lower + 0x40000000 > range.second.val())
10050 upper = lower + 0x10000000;
10060 else
10070 upper = lower + 0x40000000;
1008192826346 q node_decomp.push_back(std::make_pair(lower, upper));
1009192826346 q lower = upper;
1010192826346 q }
1011137040346 q}
1014inline void add_decomp_range(const Ranges< Uint32_Index >::Iterator& range,
1015 std::vector< std::pair< Uint32_Index, Uint32_Index > >& node_decomp)
10170 add_decomp_range(std::pair< Uint32_Index, Uint32_Index >{ range.lower_bound(), range.upper_bound() }, node_decomp);
1021template< typename Container >
1022Ranges< Uint31_Index > calc_parents(const Container& node_idxs)
1024890353 q std::vector< std::pair< Uint32_Index, Uint32_Index > > node_decomp;
1025137930353 q for (auto it = node_idxs.begin(); it != node_idxs.end(); ++it)
1026137040346 q add_decomp_range(*it, node_decomp);
1028890353 q Ranges< Uint31_Index > result;
1029890353 q result.push_back(0x80000080, 0x80000081);
1031890353 q for (std::vector< std::pair< Uint32_Index, Uint32_Index > >::const_iterator
1032193716353 q it = node_decomp.begin(); it != node_decomp.end(); ++it)
1033192826346 q {
1034192826346 q result.push_back(it->first.val(), it->second.val());
1036192826346 q uint32 lower_idx = it->first.val() & 0x7ffffffc;
1037192826346 q uint32 upper_idx = (it->second.val() - 1) & 0x7ffffffc;
1038192826346 q blur_index(2, 0x80000001, lower_idx, upper_idx, result);
1040192826346 q lower_idx = it->first.val() & 0x7fffffc0;
1041192826346 q upper_idx = (it->second.val() - 1) & 0x7fffffc0;
1042192826346 q blur_index(8, 0x80000002, lower_idx, upper_idx, result);
1044192826346 q lower_idx = it->first.val() & 0x7ffffc00;
1045192826346 q upper_idx = (it->second.val() - 1) & 0x7ffffc00;
1046192826346 q blur_index(0x20, 0x80000004, lower_idx, upper_idx, result);
1048192826346 q lower_idx = it->first.val() & 0x7fffc000;
1049192826346 q upper_idx = (it->second.val() - 1) & 0x7fffc000;
1050192826346 q blur_index(0x80, 0x80000008, lower_idx, upper_idx, result);
1052192826346 q lower_idx = it->first.val() & 0x7ffc0000;
1053192826346 q upper_idx = (it->second.val() - 1) & 0x7ffc0000;
1054192826346 q blur_index(0x200, 0x80000010, lower_idx, upper_idx, result);
1056192826346 q lower_idx = it->first.val() & 0x7fc00000;
1057192826346 q upper_idx = (it->second.val() - 1) & 0x7fc00000;
1058192826346 q blur_index(0x800, 0x80000020, lower_idx, upper_idx, result);
1060192826346 q lower_idx = it->first.val() & 0x7c000000;
1061192826346 q upper_idx = (it->second.val() - 1) & 0x7c000000;
1062192826346 q blur_index(0x2000, 0x80000040, lower_idx, upper_idx, result);
1063192826346 q }
1064890353 q result.sort();
1066890353 q return result;
1070/**--------------------------------------------------------------------------*/
1072// Calculates the ranges touched by the given bbox.
1073// This function implicitly depends on the chosen coordinate encoding.
1074inline Ranges< Uint32_Index > calc_ranges(double south, double north, double west, double east)
1075337008268 q{
1076337008268 q Ranges< Uint32_Index > ranges;
1078337008268 q uint32 isouth((south + 91.0)*10000000+0.5);
1079337008268 q uint32 inorth((north + 91.0)*10000000+0.5);
1080337008268 q int32 iwest(west*10000000 + (west > 0 ? 0.5 : -0.5));
1081337008268 q int32 ieast(east*10000000 + (east > 0 ? 0.5 : -0.5));
1083337008268 q if (west <= east)
1084337008268 q {
1085337008268 q if ((west < 0) && (east >= 0))
108711 q recursively_calc_ranges
108811 q (isouth & 0xffff0000, inorth & 0xffff0000,
108911 q 0, ieast & 0xffff0000, 1, ranges);
109011 q recursively_calc_ranges
109111 q (isouth & 0xffff0000, inorth & 0xffff0000,
109211 q iwest & 0xffff0000, 0xffff0000, 1, ranges);
1094337007267 q else
1095337007267 q recursively_calc_ranges
1096337007267 q (isouth & 0xffff0000, inorth & 0xffff0000,
1097337007267 q iwest & 0xffff0000, ieast & 0xffff0000, 1, ranges);
1098337008268 q }
10990 else
11000 {
11010 if (west < 0)
11020 {
11030 recursively_calc_ranges
11040 (isouth & 0xffff0000, inorth & 0xffff0000,
11050 iwest & 0xffff0000, 0xffff0000, 1, ranges);
11060 recursively_calc_ranges
11070 (isouth & 0xffff0000, inorth & 0xffff0000,
11080 0, int32(180.0*10000000 + 0.5) & 0xffff0000, 1, ranges);
11090 }
11100 else
11110 recursively_calc_ranges
11120 (isouth & 0xffff0000, inorth & 0xffff0000,
11130 iwest & 0xffff0000, int32(180.0*10000000 + 0.5) & 0xffff0000, 1, ranges);
11150 if (east > 0)
11160 {
11170 recursively_calc_ranges
11180 (isouth & 0xffff0000, inorth & 0xffff0000,
11190 int32(-180.0*10000000 - 0.5) & 0xffff0000, 0xffff0000, 1, ranges);
11200 recursively_calc_ranges
11210 (isouth & 0xffff0000, inorth & 0xffff0000,
11220 0, ieast & 0xffff0000, 1, ranges);
11230 }
11240 else
11250 recursively_calc_ranges
11260 (isouth & 0xffff0000, inorth & 0xffff0000,
11270 int32(-180.0*10000000 - 0.5) & 0xffff0000, ieast & 0xffff0000, 1, ranges);
11280 }
1129337008268 q ranges.sort();
1131337008268 q return ranges;
1132337008268 q}
1135inline Ranges< Uint32_Index > get_ranges_32(double south, double north, double west, double east)
1137222193 q return ::calc_ranges(south, north, west, east);
1141// Adds recursively the ranges based on the given products of
1142// closed intervals.
1143// The expected assertion for the recursion is that the indices are equal
1144// on the first bitlevel bits. Also, indexes must have the last 16 bit set to zero.
1145inline void recursively_calc_ranges
1146 (uint32 south, uint32 north, int32 west, int32 east,
1147 uint32 bitlevel, Ranges< Uint32_Index >& ranges)
11486181741268 q{
11496181741268 q int32 dist = ((0xffff0000u>>bitlevel)&0xffff0000);
1151 // If the difference is exactly dist, the indices fill the whole square
1152 // and we can add this square to the ranges.
11536181741268 q if ((south + dist == north) && (west + dist == east))
1154740746268 q {
1155740746268 q ranges.push_back(ll_upper_(south, west), ll_upper_(north, east) + 1);
1156740746268 q return;
1157740746268 q }
1159 // Shift dist to obtain a proper recursion.
11605440995268 q dist = ((dist>>1)&0xffff0000);
11625440995268 q if ((north | dist) != (south | dist))
1163187192252 q {
1164 // We need to split between northern and southern part.
1165187192252 q if ((east | dist) != (west | dist))
11666413173 q {
1167 // We also need to split between western and eastern part.
11686413173 q recursively_calc_ranges
11696413173 q (south, south | dist, west, west | dist,
11706413173 q bitlevel + 1, ranges);
11716413173 q recursively_calc_ranges
11726413173 q (south, south | dist, (west | dist) + 0x10000, east,
11736413173 q bitlevel + 1, ranges);
11746413173 q recursively_calc_ranges
11756413173 q ((south | dist) + 0x10000, north, west, west | dist,
11766413173 q bitlevel + 1, ranges);
11776413173 q recursively_calc_ranges
11786413173 q ((south | dist) + 0x10000, north, (west | dist) + 0x10000, east,
11796413173 q bitlevel + 1, ranges);
11806413173 q }
1181180779251 q else
1182180779251 q {
1183 // We don't need to split because east and west lie in the
1184 // same half of the current square.
1185180779251 q recursively_calc_ranges
1186180779251 q (south, south | dist, west, east,
1187180779251 q bitlevel + 1, ranges);
1188180779251 q recursively_calc_ranges
1189180779251 q ((south | dist) + 0x10000, north, west, east,
1190180779251 q bitlevel + 1, ranges);
1191180779251 q }
1192187192252 q }
11935253803268 q else
11945253803268 q {
1195 // We don't need to split because north and south lie in the
1196 // same half of the current square.
11975253803268 q if ((east | dist) != (west | dist))
1198203719254 q {
1199 // We only need to split between western and eastern part.
1200203719254 q recursively_calc_ranges
1201203719254 q (south, north, west, west | dist,
1202203719254 q bitlevel + 1, ranges);
1203203719254 q recursively_calc_ranges
1204203719254 q (south, north, (west | dist) + 0x10000, east,
1205203719254 q bitlevel + 1, ranges);
1206203719254 q }
12075050084268 q else
1208 // We need no split at all.
12095050084268 q recursively_calc_ranges
12105050084268 q (south, north, west, east, bitlevel + 1, ranges);
12115253803268 q }
12125440995268 q}
1215/*---------------------------------------------------------------------------*/
1218inline uint32 ilat_(double lat)
12195045085372 q{
12205045085372 q return ((lat + 91.0)*10000000+0.5);
12215045085372 q}
1224inline int32 ilon_(double lon)
12255045085372 q{
12265045085372 q return (lon*10000000 + (lon > 0 ? 0.5 : -0.5));
12275045085372 q}
1230inline uint32 ll_upper_(double lat, double lon)
12315037400119 q{
12325037400119 q uint32 temp = ll_upper(ilat_(lat), ilon_(lon));
12335037400119 q return (temp ^ 0x40000000);
12345037400119 q}
1237inline uint32 ll_lower(uint32 ilat, int32 ilon)
1238515823102 q{
1239515823102 q uint32 result(0);
12418768991102 q for (uint32 i(0); i < 16; ++i)
12428253168102 q {
12438253168102 q result |= ((0x1<<i)&ilat)<<(i+1);
12448253168102 q result |= ((0x1<<i)&(uint32)ilon)<<i;
12458253168102 q }
1247515823102 q return result;
1248515823102 q}
1251inline uint32 ll_lower(double lat, double lon)
125339126 q return ll_lower(ilat_(lat), ilon_(lon));
1257inline uint32 ilat(double lat)
1258880038118 q{
1259880038118 q return (lat + 91.0)*10000000+0.5;
1260880038118 q}
1263inline int32 ilon(double lon)
126463614163 q{
126563614163 q return lon*10000000 + (lon > 0 ? 0.5 : -0.5);
126663614163 q}
1269// convert interleaved coordinates to plain integers
1270inline uint32 ilat(uint32 ll_upper, uint32 ll_lower)
12711778986911449 q{
12721778986911449 q uint32 upper = ll_upper & 0xaaaaaaaa;
12731778986911449 q upper = (upper | (upper<<1)) & 0xcccccccc;
12741778986911449 q upper = (upper | (upper<<2)) & 0xf0f0f0f0;
12751778986911449 q upper = (upper | (upper<<4)) & 0xff00ff00;
12761778986911449 q upper = (upper | (upper<<8)) & 0xffff0000;
12781778986911449 q uint32 lower = ll_lower & 0xaaaaaaaa;
12791778986911449 q lower = (lower | (lower>>1)) & 0x99999999;
12801778986911449 q lower = (lower | (lower>>2)) & 0x87878787;
12811778986911449 q lower = (lower | (lower>>4)) & 0x807f807f;
12821778986911449 q lower = (lower | (lower>>8)) & 0x80007fff;
12831778986911449 q lower = (lower | (lower>>16)) & 0x0000ffff;
12851778986911449 q return (upper | lower);
12861778986911449 q}
1289inline double lat(uint32 ll_upper, uint32 ll_lower)
129039983442432 q{
129139983442432 q return ((double)ilat(ll_upper, ll_lower))/10000000 - 91.0;
129239983442432 q}
1294inline double lat(uint32 ilat)
12956535911 q{
12966535911 q return ((double)ilat)/10000000 - 91.0;
12976535911 q}
1300// convert interleaved coordinates to plain integers
1301inline int32 ilon(uint32 ll_upper, uint32 ll_lower)
13021781881462450 q{
13031781881462450 q uint32 upper = (ll_upper ^ 0x40000000) & 0x55555555;
13041781881462450 q upper = (upper | (upper<<1)) & 0x99999999;
13051781881462450 q upper = (upper | (upper<<2)) & 0xe1e1e1e1;
13061781881462450 q upper = (upper | (upper<<4)) & 0xfe01fe01;
13071781881462450 q upper = (upper | (upper<<8)) & 0xfffe0001;
13081781881462450 q upper = (upper | (upper<<16)) & 0xffff0000;
13101781881462450 q uint32 lower = ll_lower & 0x55555555;
13111781881462450 q lower = (lower | (lower>>1)) & 0x33333333;
13121781881462450 q lower = (lower | (lower>>2)) & 0x0f0f0f0f;
13131781881462450 q lower = (lower | (lower>>4)) & 0x00ff00ff;
13141781881462450 q lower = (lower | (lower>>8)) & 0x0000ffff;
13161781881462450 q return (upper | lower);
13171781881462450 q}
1320inline double lon(uint32 ll_upper, uint32 ll_lower)
132142884825432 q{
132242884825432 q return ((double)ilon(ll_upper, ll_lower))/10000000;
132342884825432 q}
1325inline double lon(int32 ilon)
132629883767 q{
132729883767 q return ((double)ilon)/10000000;
132829883767 q}
1331inline bool is_compound_idx(Uint31_Index idx)
13326223960 q{
13336223960 q return idx.val() & 0x80000000u;
13346223960 q}
1337#endif