Overpass API regression suite coverage (Nova Scotia) / template_db/ranges.def.h

template_db/ranges.def.h

86 of 86 instrumented lines run by the suite (100.0%) 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___TEMPLATE_DB__RANGES_DEF_H
20#define DE__OSM3S___TEMPLATE_DB__RANGES_DEF_H
22#include "ranges.h"
24#include <algorithm>
27template< typename Index >
28Ranges< Index > Ranges< Index >::intersect(const Ranges< Index >& rhs) const
2910177462 q{
3010177462 q if (rhs.is_global())
3115179 q return *this;
3210026443 q else if (this->is_global())
338871430 q return rhs;
351155334 q Ranges< Index > result;
361155334 q auto it_a = data.begin();
371155334 q auto it_b = rhs.data.begin();
39525591334 q while (it_a != data.end() && it_b != rhs.data.end())
40524436154 q {
41524436154 q if (!(it_a->first < it_b->second))
42461483148 q ++it_b;
4362953154 q else if (!(it_b->first < it_a->second))
4425839152 q ++it_a;
4537114146 q else if (it_b->second < it_a->second)
461802872 q {
471802872 q result.push_back(std::max(it_a->first, it_b->first), it_b->second);
481802872 q ++it_b;
491802872 q }
5019086143 q else
5119086143 q {
5219086143 q result.push_back(std::max(it_a->first, it_b->first), it_a->second);
5319086143 q ++it_a;
5419086143 q }
55524436154 q }
571155334 q return result;
5810177462 q}
61template< typename Index >
62Ranges< Index > Ranges< Index >::union_(const Ranges< Index >& rhs) const
633150136 q{
643150136 q Ranges< Index > result;
663150136 q auto it_a = data.begin();
673150136 q auto it_b = rhs.data.begin();
69889992136 q while (it_a != data.end() && it_b != rhs.data.end())
7088684250 q {
7188684250 q if (it_a->first < it_b->first)
7269170245 q {
7369170245 q result.data.push_back(*it_a);
7469170245 q ++it_a;
7569170245 q }
7619514045 q else
7719514045 q {
7819514045 q result.data.push_back(*it_b);
7919514045 q ++it_b;
8019514045 q }
8188684250 q }
8251957136 q while (it_a != data.end())
834880733 q {
844880733 q result.data.push_back(*it_a);
854880733 q ++it_a;
864880733 q }
87156662136 q while (it_b != rhs.data.end())
88153512116 q {
89153512116 q result.data.push_back(*it_b);
90153512116 q ++it_b;
91153512116 q }
93 //result.sort();
943150136 q return result;
953150136 q}
98template< typename Index >
99Ranges< Index > Ranges< Index >::skip_start(Index lower_bound) const
101961452 q Ranges< Index > result;
102961452 q for (const auto& i : data)
1031190802452 q {
1041190802452 q if (lower_bound < i.second)
1051190802452 q result.data.push_back({ std::max(i.first, lower_bound), i.second });
1061190802452 q }
107961452 q return result;
111template< typename Index >
112void Ranges< Index >::sort()
113357056490 q{
114// int order = 0;
115// uint64_t size = data.size();
116// while (size)
117// {
118// size = size>>1;
119// ++order;
120// }
121// static int count = 0;
122// static int total = 0;
123// static std::vector< int > stat;
124// if (stat.size() <= order)
125// stat.resize(order+1);
126// if (data.size() > 2*1024*1024)
127// ++total;
128// ++stat[order];
129// total += data.size();
130// if (++count % 200 == 0)
131// {
132// std::cerr<<"#Ranges::sort "<<count<<' '<<total<<'\n';
133// for (int i = 0; i < stat.size(); ++i)
134// std::cerr<<'\t'<<stat[i];
135// std::cerr<<'\n';
136// }
138357056490 q std::sort(data.begin(), data.end());
140357056490 q if (!data.empty())
141344363461 q {
142344363461 q decltype(data) result;
143344363461 q auto it = data.begin();
144344363461 q std::pair< Index, Index > buf = *it;
14513857582461 q for (++it; it != data.end(); ++it)
14613513219433 q {
14713513219433 q if (buf.second < it->first)
1481799503431 q {
1491799503431 q result.push_back(buf);
1501799503431 q buf = *it;
1511799503431 q }
15211713716413 q else
15311713716413 q buf.second = std::max(buf.second, it->second);
15413513219433 q }
155344363461 q result.push_back(buf);
156344363461 q result.swap(data);
157344363461 q }
158357056490 q}
161#endif