Overpass API regression suite coverage (Nova Scotia) / overpass_api/data/collect_items.h

overpass_api/data/collect_items.h

350 of 397 instrumented lines run by the suite (88.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__DATA__COLLECT_ITEMS_H
20#define DE__OSM3S___OVERPASS_API__DATA__COLLECT_ITEMS_H
22#include "../dispatch/resource_manager.h"
23#include "abstract_processing.h"
24#include "filenames.h"
26#include <exception>
29113699070187 qinline uint64 timestamp_of(const Attic< Node_Skeleton >& skel) { return skel.timestamp; }
301496533163 qinline uint64 timestamp_of(const Attic< Way_Skeleton >& skel) { return skel.timestamp; }
3114824091 qinline uint64 timestamp_of(const Attic< Relation_Skeleton >& skel) { return skel.timestamp; }
33307106287191 qinline uint64 timestamp_of(const Node_Skeleton& skel) { return NOW; }
344150918169 qinline uint64 timestamp_of(const Way_Skeleton& skel) { return NOW; }
3513626591 qinline uint64 timestamp_of(const Relation_Skeleton& skel) { return NOW; }
38template < class Index, class Object, class Iterator, class Predicate >
39void reconstruct_items(
40 Iterator& it, Iterator end, Index index,
41 const Predicate& predicate,
42 std::vector< Object >& result,
43 std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,
44 uint64 timestamp, uint32& count)
452366304191 q{
46219660619191 q while (!(it == end) && it.index() == index)
47217294315191 q {
48217294315191 q ++count;
49217294315191 q if (timestamp < timestamp_of(it.object()))
50193148819191 q {
51193148819191 q timestamp_by_id.push_back(std::make_pair(it.object().id, timestamp_of(it.object())));
52193148819191 q if (predicate.match(it.object()))
5310362223189 q result.push_back(it.object());
54193148819191 q }
55217294315191 q ++it;
56217294315191 q }
572366304191 q}
60class Statement;
63class Health_Guard
65public:
6615104513 q Health_Guard(const Statement* stmt_, Resource_Manager& rman_) : stmt(stmt_), rman(rman_) {}
680 void log_and_display_error(const std::string& message) const { rman.log_and_display_error(message); }
69 bool check(uint32 extra_time = 0, uint64 extra_space = 0)
7015499478 q { return (stmt) && rman.health_check(*stmt, extra_time, extra_space); }
72private:
73 const Statement* stmt;
74 Resource_Manager& rman;
75};
78class Request_Context
80public:
8112804573 q Request_Context(const Statement* stmt_, Resource_Manager& rman_) : stmt(stmt_), rman(rman_) {}
8315104513 q Health_Guard get_health_guard() { return Health_Guard(stmt, rman); }
8418236570 q uint64 get_desired_timestamp() const { return rman.get_desired_timestamp(); }
85 File_Blocks_Index_Base* data_index(const File_Properties* file_properties)
868837563 q { return rman.get_transaction()->data_index(file_properties); }
87 Random_File_Index* random_index(const File_Properties* file_properties)
883321 q { return rman.get_transaction()->random_index(file_properties); }
90private:
91 const Statement* stmt;
92 Resource_Manager& rman;
93};
96template < class Index, class Object, class Attic_Iterator, class Current_Iterator, class Predicate >
97void reconstruct_items(Health_Guard& health_guard,
98 Current_Iterator& current_it, Current_Iterator current_end,
99 Attic_Iterator& attic_it, Attic_Iterator attic_end, Index& idx,
100 const Predicate& predicate,
101 std::vector< Object >& result, std::vector< Attic< Object > >& attic_result,
102 std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,
103 uint64 timestamp)
1041282062201 q{
1051282062201 q std::vector< Object > skels;
1061282062201 q std::vector< Attic< typename Object::Delta > > deltas;
1071282062201 q std::vector< std::pair< typename Object::Id_Type, uint64 > > local_timestamp_by_id;
10915693994201 q while (!(current_it == current_end) && current_it.index() == idx)
11014411932185 q {
11114411932185 q timestamp_by_id.push_back(std::make_pair(current_it.object().id, NOW));
11214411932185 q local_timestamp_by_id.push_back(std::make_pair(current_it.object().id, NOW));
11314411932185 q skels.push_back(current_it.object());
11414411932185 q ++current_it;
11514411932185 q }
11724303261201 q while (!(attic_it == attic_end) && attic_it.index() == idx)
11823021199200 q {
11923021199200 q if (timestamp < attic_it.object().timestamp)
12014305571197 q {
12114305571197 q timestamp_by_id.push_back(std::make_pair(attic_it.object().id, attic_it.object().timestamp));
12214305571197 q local_timestamp_by_id.push_back(std::make_pair(attic_it.object().id, attic_it.object().timestamp));
12314305571197 q deltas.push_back(attic_it.object());
12414305571197 q }
12523021199200 q ++attic_it;
12623021199200 q }
1281282062201 q std::vector< const Attic< typename Object::Delta >* > delta_refs;
1291282062201 q delta_refs.reserve(deltas.size());
1301282062201 q for (typename std::vector< Attic< typename Object::Delta > >::const_iterator it = deltas.begin();
13115587633201 q it != deltas.end(); ++it)
13214305571197 q delta_refs.push_back(&*it);
1341282062201 q std::sort(skels.begin(), skels.end());
1351282062201 q std::sort(delta_refs.begin(), delta_refs.end(), Delta_Ref_Comparator< Attic< typename Object::Delta > >());
1361282062201 q std::sort(local_timestamp_by_id.begin(), local_timestamp_by_id.end());
1381282062201 q std::vector< Attic< Object > > attics;
1391282062201 q typename std::vector< Object >::const_iterator skels_it = skels.begin();
1401282062201 q Object reference;
1411282062201 q for (typename std::vector< const Attic< typename Object::Delta >* >::const_iterator it = delta_refs.begin();
14215587633201 q it != delta_refs.end(); ++it)
14314305571197 q {
14414305571197 q if (!(reference.id == (*it)->id))
1455700175197 q {
14614846010197 q while (skels_it != skels.end() && skels_it->id < (*it)->id)
1479145835180 q ++skels_it;
1485700175197 q if (skels_it != skels.end() && skels_it->id == (*it)->id)
1493716111181 q reference = *skels_it;
1501984064188 q else
1511984064188 q reference = Object();
1525700175197 q }
15314305571197 q try
15414305571197 q {
15514305571197 q Attic< Object > attic_obj = Attic< Object >((*it)->expand(reference), (*it)->timestamp);
15614305571197 q if (attic_obj.id.val() != 0)
15714305571197 q {
15814305571197 q reference = attic_obj;
15914305571197 q typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::const_iterator
16014305571197 q tit = std::lower_bound(local_timestamp_by_id.begin(), local_timestamp_by_id.end(),
16114305571197 q std::make_pair((*it)->id, 0ull));
16214305571197 q if (tit != local_timestamp_by_id.end() && tit->first == (*it)->id && tit->second == (*it)->timestamp)
1635700175197 q attics.push_back(attic_obj);
16414305571197 q }
1650 else
1660 {
167 // Relation_Delta without a reference of the same index
1680 std::ostringstream out;
1690 out<<name_of_type< Object >()<<" "<<(*it)->id.val()<<" cannot be expanded at timestamp "
1700 <<Timestamp((*it)->timestamp).str()<<".";
1710 health_guard.log_and_display_error(out.str());
1720 }
17314305571197 q }
17414305571197 q catch (const std::exception& e)
17514305571197 q {
1760 std::ostringstream out;
1770 out<<name_of_type< Object >()<<" "<<(*it)->id.val()<<" cannot be expanded at timestamp "
1780 <<Timestamp((*it)->timestamp).str()<<": "<<e.what();
1790 health_guard.log_and_display_error(out.str());
1800 }
18114305571197 q }
1836982237201 q for (typename std::vector< Attic< Object > >::const_iterator it = attics.begin(); it != attics.end(); ++it)
1845700175197 q {
1855700175197 q if (predicate.match(*it))
1861644773171 q attic_result.push_back(*it);
1875700175197 q }
18915693994201 q for (typename std::vector< Object >::const_iterator it = skels.begin(); it != skels.end(); ++it)
19014411932185 q {
19114411932185 q if (predicate.match(*it))
1924287183177 q result.push_back(*it);
19314411932185 q }
1941282062201 q}
197template < class Object >
198void filter_items_by_timestamp(
199 const std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,
200 std::vector< Object >& result)
2014930428232 q{
2024930428232 q typename std::vector< Object >::iterator target_it = result.begin();
2034930428232 q for (typename std::vector< Object >::iterator it2 = result.begin();
20421224607232 q it2 != result.end(); ++it2)
20516294179224 q {
20616294179224 q typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::const_iterator
20716294179224 q tit = std::lower_bound(timestamp_by_id.begin(), timestamp_by_id.end(),
20816294179224 q std::make_pair(it2->id, 0ull));
20916294179224 q if (tit != timestamp_by_id.end() && tit->first == it2->id && tit->second == timestamp_of(*it2))
21014635151224 q {
21114635151224 q *target_it = *it2;
21214635151224 q ++target_it;
21314635151224 q }
21416294179224 q }
2154930428232 q result.erase(target_it, result.end());
2164930428232 q}
219template < class Index, class Object >
220void filter_items_by_timestamp(
221 const std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,
222 std::map< Index, std::vector< Object > >& result)
224 for (typename std::map< Index, std::vector< Object > >::iterator it = result.begin();
225 it != result.end(); ++it)
226 filter_items_by_timestamp(timestamp_by_id, it->second);
230template< typename Object >
231void check_for_duplicated_objects(
232 const std::vector< std::pair< typename Object::Id_Type, uint64 > >& timestamp_by_id,
233 Health_Guard& health_guard)
235 // Debug-Feature. Can be disabled once no further bugs appear
236 for (typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::size_type i = 0;
237 i+1 < timestamp_by_id.size(); ++i)
238 {
239 if (timestamp_by_id[i].second == timestamp_by_id[i+1].second
240 && timestamp_by_id[i].first == timestamp_by_id[i+1].first)
241 {
242 std::ostringstream out;
243 out<<name_of_type< Object >()<<" "<<timestamp_by_id[i].first.val()
244 <<" appears multiple times at timestamp "<<Timestamp(timestamp_by_id[i].second).str();
245 health_guard.log_and_display_error(out.str());
246 }
247 }
251template < class Index, class Object, class Current_Iterator, class Attic_Iterator, class Predicate >
252bool collect_items_by_timestamp(Health_Guard&& health_guard,
253 Current_Iterator current_begin, Current_Iterator current_end,
254 Attic_Iterator attic_begin, Attic_Iterator attic_end,
255 const Predicate& predicate, Index* cur_idx, uint64 timestamp,
256 std::map< Index, std::vector< Object > >& result,
257 std::map< Index, std::vector< Attic< Object > > >& attic_result)
2591294196 q uint32 count = 0;
2601184446196 q while (!(current_begin == current_end) || !(attic_begin == attic_end))
2611183152191 q {
2621183152191 q std::vector< std::pair< typename Object::Id_Type, uint64 > > timestamp_by_id;
2641183152191 q bool too_much_data = false;
2651183152191 q if (++count >= 128*1024)
266143353 q {
267143353 q count = 0;
268143353 q health_guard.check(0, eval_map(result));
269143353 q health_guard.check(0, eval_map(attic_result));
270143353 q }
2711183152191 q Index index =
2721183152191 q (attic_begin == attic_end ||
2731183152191 q (!(current_begin == current_end) && current_begin.index() < attic_begin.index())
2741183152191 q ? current_begin.index() : attic_begin.index());
2751183152191 q if (too_much_data && cur_idx)
2760 {
2770 *cur_idx = index;
2780 return true;
2790 }
2811183152191 q reconstruct_items(
2821183152191 q current_begin, current_end, index, predicate, result[index], timestamp_by_id, timestamp, count);
2831183152191 q reconstruct_items(
2841183152191 q attic_begin, attic_end, index, predicate, attic_result[index], timestamp_by_id, timestamp, count);
2861183152191 q std::sort(timestamp_by_id.begin(), timestamp_by_id.end());
2881183152191 q filter_items_by_timestamp(timestamp_by_id, result[index]);
2891183152191 q filter_items_by_timestamp(timestamp_by_id, attic_result[index]);
291 //check_for_duplicated_objects< Object >(timestamp_by_id, rman);
2921183152191 q }
2931294196 q return false;
297template < class Index, class Current_Iterator, class Attic_Iterator, class Predicate >
298bool collect_items_by_timestamp(Health_Guard&& health_guard,
299 Current_Iterator current_begin, Current_Iterator current_end,
300 Attic_Iterator attic_begin, Attic_Iterator attic_end,
301 const Predicate& predicate, Index* cur_idx, uint64 timestamp,
302 std::map< Index, std::vector< Relation_Skeleton > >& result,
303 std::map< Index, std::vector< Attic< Relation_Skeleton > > >& attic_result)
305461138 q uint32 count = 0;
306225113138 q while (!(current_begin == current_end) || !(attic_begin == attic_end))
307224652119 q {
308224652119 q std::vector< std::pair< Relation_Skeleton::Id_Type, uint64 > > timestamp_by_id;
310224652119 q bool too_much_data = false;
311224652119 q if (++count >= 128*1024)
3120 {
3130 count = 0;
3140 health_guard.check(0, eval_map(result));
3150 health_guard.check(0, eval_map(attic_result));
3160 }
317224652119 q Index index =
318224652119 q (attic_begin == attic_end ||
319224652119 q (!(current_begin == current_end) && current_begin.index() < attic_begin.index())
320224652119 q ? current_begin.index() : attic_begin.index());
321224652119 q if (too_much_data && cur_idx)
3220 {
3230 *cur_idx = index;
3240 return true;
3250 }
327224652119 q reconstruct_items(health_guard, current_begin, current_end, attic_begin, attic_end, index,
328224652119 q predicate, result[index], attic_result[index], timestamp_by_id, timestamp);
330224652119 q std::sort(timestamp_by_id.begin(), timestamp_by_id.end());
332224652119 q filter_items_by_timestamp(timestamp_by_id, result[index]);
333224652119 q filter_items_by_timestamp(timestamp_by_id, attic_result[index]);
335 //check_for_duplicated_objects< Relation_Skeleton >(timestamp_by_id, rman);
336224652119 q }
337461138 q return false;
341template< typename Index, typename Object >
342struct Timeless
344 Timeless& swap(
345 std::map< Index, std::vector< Object > >& rhs_current,
346 std::map< Index, std::vector< Attic< Object > > >& rhs_attic)
3473803239 q {
3483803239 q current.swap(rhs_current);
3493803239 q attic.swap(rhs_attic);
3503803239 q return *this;
3513803239 q }
353 Timeless& sort()
354406874 q {
355406874 q sort_second(current);
356406874 q sort_second(attic);
357406874 q return *this;
358406874 q }
360 Timeless& set_union(const Timeless< Index, Object >& rhs)
36139265 q {
36239265 q indexed_set_union(current, rhs.current);
36339265 q indexed_set_union(attic, rhs.attic);
36439265 q return *this;
36539265 q }
367 template< typename Predicate >
368 Timeless& filter_items(const Predicate& predicate)
3705245 q ::filter_items(predicate, current);
3715245 q ::filter_items(predicate, attic);
3725245 q return *this;
375 Timeless& filter_by_id(const std::vector< typename Object::Id_Type >& ids);
377 std::map< Index, std::vector< Object > > current;
378 std::map< Index, std::vector< Attic< Object > > > attic;
379};
382template < class Index, class Current_Iterator, class Attic_Iterator, class Predicate >
383bool collect_items_by_timestamp(Health_Guard&& health_guard,
384 Current_Iterator current_begin, Current_Iterator current_end,
385 Attic_Iterator attic_begin, Attic_Iterator attic_end,
386 const Predicate& predicate, Index* cur_idx, uint64 timestamp,
387 std::map< Index, std::vector< Way_Skeleton > >& result,
388 std::map< Index, std::vector< Attic< Way_Skeleton > > >& attic_result)
390716188 q uint32 count = 0;
3911058126188 q while (!(current_begin == current_end) || !(attic_begin == attic_end))
3921057410182 q {
3931057410182 q std::vector< std::pair< Way_Skeleton::Id_Type, uint64 > > timestamp_by_id;
3951057410182 q bool too_much_data = false;
3961057410182 q if (++count >= 128*1024)
3970 {
3980 count = 0;
3990 health_guard.check(0, eval_map(result));
4000 health_guard.check(0, eval_map(attic_result));
4010 }
4021057410182 q Index index =
4031057410182 q (attic_begin == attic_end ||
4041057410182 q (!(current_begin == current_end) && current_begin.index() < attic_begin.index())
4051057410182 q ? current_begin.index() : attic_begin.index());
4061057410182 q if (too_much_data && cur_idx)
4070 {
4080 *cur_idx = index;
4090 return true;
4100 }
4121057410182 q reconstruct_items(health_guard, current_begin, current_end, attic_begin, attic_end, index,
4131057410182 q predicate, result[index], attic_result[index], timestamp_by_id, timestamp);
4151057410182 q std::sort(timestamp_by_id.begin(), timestamp_by_id.end());
4171057410182 q filter_items_by_timestamp(timestamp_by_id, result[index]);
4181057410182 q filter_items_by_timestamp(timestamp_by_id, attic_result[index]);
420 //check_for_duplicated_objects< Way_Skeleton >(timestamp_by_id, rman);
4211057410182 q }
422716188 q return false;
426template < class Index, class Object, class Container, class Predicate >
427void collect_items_discrete(Transaction& transaction,
428 File_Properties& file_properties,
429 const Container& req, const Predicate& predicate,
430 std::map< Index, std::vector< Object > >& result)
432 Block_Backend< Index, Object, typename Container::const_iterator > db
433 (transaction.data_index(&file_properties));
434 for (auto it = db.discrete_begin(req.begin(), req.end()); !(it == db.discrete_end()); ++it)
435 {
436 if (predicate.match(it.handle()))
437 result[it.index()].push_back(it.object());
438 }
442// Used by Set_Comparison
443template < class Index, class Object, class Container, class Predicate >
444void collect_items_discrete(Request_Context& context,
445 const Container& req, const Predicate& predicate, uint64 timestamp,
446 std::map< Index, std::vector< Object > >& result,
447 std::map< Index, std::vector< Attic< Object > > >& attic_result)
4491639225 q Block_Backend< Index, Object, typename Container::const_iterator > current_db(
4501639225 q context.data_index(current_skeleton_file_properties< Object >()));
4511639225 q if (timestamp == NOW)
4531014733145 q for (auto it = current_db.discrete_begin(req.begin(), req.end()); !(it == current_db.discrete_end()); ++it)
4541014086115 q {
4551014086115 q if (predicate.match(it.handle()))
45661409104 q result[it.index()].push_back(it.object());
4571014086115 q }
459992110 q else
461992110 q Block_Backend< Index, Attic< typename Object::Delta >, typename Container::const_iterator > attic_db(
462992110 q context.data_index(attic_skeleton_file_properties< Object >()));
464992110 q collect_items_by_timestamp(context.get_health_guard(),
465992110 q current_db.discrete_begin(req.begin(), req.end()), current_db.discrete_end(),
466992110 q attic_db.discrete_begin(req.begin(), req.end()), attic_db.discrete_end(),
467992110 q predicate, (Index*)0, timestamp, result, attic_result);
472template < class Index, class Object, class Container, class Predicate >
473void collect_items_discrete(Request_Context& context,
474 const Container& req, const Predicate& predicate,
475 std::map< Index, std::vector< Object > >& result,
476 std::map< Index, std::vector< Attic< Object > > >& attic_result)
478505203 q collect_items_discrete(context, req, predicate, context.get_desired_timestamp(), result, attic_result);
482template< typename Index, typename Object, typename Predicate >
483Timeless< Index, Object > collect_items_range(Request_Context& context,
484 const Ranges< Index >& ranges, const Predicate& predicate)
48517285462 q{
48617285462 q Timeless< Index, Object > result;
48717285462 q if (ranges.empty() || !predicate.possible())
48813640403 q return result;
4903645366 q Block_Backend< Index, Object > current_db
4913645366 q (context.data_index(current_skeleton_file_properties< Object >()));
4923645366 q if (context.get_desired_timestamp() == NOW)
4932541257 q {
494305819893257 q for (auto it = current_db.range_begin(ranges); !(it == current_db.range_end()); ++it)
495305817352256 q {
496305817352256 q if (predicate.match(it.handle()))
49725046007256 q result.current[it.index()].push_back(it.object());
498305817352256 q }
4992541257 q }
5001104141 q else
5011104141 q {
5021104141 q Block_Backend< Index, Attic< typename Object::Delta > > attic_db
5031104141 q (context.data_index(attic_skeleton_file_properties< Object >()));
5041104141 q collect_items_by_timestamp(context.get_health_guard(),
5051104141 q current_db.range_begin(ranges), current_db.range_end(),
5061104141 q attic_db.range_begin(ranges), attic_db.range_end(),
5071104141 q predicate, (Index*)0, context.get_desired_timestamp(), result.current, result.attic);
5081104141 q }
5093645366 q return result;
51017285462 q}
513template < class Index, class Object, class Predicate >
514bool collect_items_range(Request_Context& context,
515 const Ranges< Index >& ranges, const Predicate& predicate, Index& cur_idx,
516 std::map< Index, std::vector< Object > >& result,
517 std::map< Index, std::vector< Attic< Object > > >& attic_result)
519961452 q Ranges< Index > shortened = ranges.skip_start(cur_idx);
520961452 q Block_Backend< Index, Object > current_db(
521961452 q context.data_index(current_skeleton_file_properties< Object >()));
523961452 q if (context.get_desired_timestamp() == NOW)
525605307 q uint32 count = 0;
526605307 q bool too_much_data = false;
528190797133307 q for (auto it = current_db.range_begin(shortened); !(it == current_db.range_end()); ++it)
529190796528303 q {
530190796528303 q if (too_much_data && !(cur_idx == it.index()))
5310 {
5320 cur_idx = it.index();
5330 return true;
5340 }
535190796528303 q if (++count >= 256*1024)
53665778 q {
53765778 q count = 0;
53865778 q too_much_data = context.get_health_guard().check(0, eval_map(result));
53965778 q cur_idx = it.index();
54065778 q }
541190796528303 q if (predicate.match(it.handle()))
54259731706301 q result[it.index()].push_back(it.object());
543190796528303 q }
545605307 q return false;
547356183 q else
549356183 q Block_Backend< Index, Attic< typename Object::Delta > > attic_db(
550356183 q context.data_index(attic_skeleton_file_properties< Object >()));
552356183 q return collect_items_by_timestamp(context.get_health_guard(),
553356183 q current_db.range_begin(shortened), current_db.range_end(),
554356183 q attic_db.range_begin(shortened), attic_db.range_end(),
555356183 q predicate, &cur_idx, context.get_desired_timestamp(), result, attic_result);
560// Current called olny for areas and only from Query_Statement.
561template < class Index, class Object, class Predicate >
562void collect_items_flat(Request_Context& context,
563 File_Properties& file_properties, const Predicate& predicate,
564 std::map< Index, std::vector< Object > >& result)
5665145 q uint32 count = 0;
5675145 q Block_Backend< Index, Object > db(context.data_index(&file_properties));
5685145 q for (typename Block_Backend< Index, Object >::Flat_Iterator
56939805545 q it(db.flat_begin()); !(it == db.flat_end()); ++it)
57039800445 q {
57139800445 q if (++count >= 256*1024)
5720 {
5730 count = 0;
5740 context.get_health_guard().check(0, eval_map(result));
5750 }
57639800445 q if (predicate.match(it.handle()))
5771027245 q result[it.index()].push_back(it.object());
57839800445 q }
582template < class Index, class Object, class Predicate >
583void collect_items_flat(
584 Request_Context& context, const Predicate& predicate,
585 std::map< Index, std::vector< Object > >& result,
586 std::map< Index, std::vector< Attic< Object > > >& attic_result)
5886731 q Block_Backend< Index, Object > current_db
5896731 q (context.data_index(current_skeleton_file_properties< Object >()));
5916731 q if (context.get_desired_timestamp() == NOW)
5934821 q uint32 count = 0;
594102508821 q for (auto it = current_db.flat_begin(); !(it == current_db.flat_end()); ++it)
595102504021 q {
596102504021 q if (++count >= 256*1024)
5970 {
5980 count = 0;
5990 context.get_health_guard().check(0, eval_map(result));
6000 }
601102504021 q if (predicate.match(it.handle()))
60217211 q result[it.index()].push_back(it.object());
603102504021 q }
6051912 q else
6071912 q Block_Backend< Index, Attic< typename Object::Delta > > attic_db
6081912 q (context.data_index(attic_skeleton_file_properties< Object >()));
6101912 q collect_items_by_timestamp(context.get_health_guard(),
6111912 q current_db.flat_begin(), current_db.flat_end(),
6121912 q attic_db.flat_begin(), attic_db.flat_end(),
6131912 q predicate, (Index*)0, context.get_desired_timestamp(), result, attic_result);
618/* Returns for the given std::set of ids the std::set of corresponding indexes.
619 * The function requires that the ids are sorted ascending by id.
620 */
621template< typename Index, typename Skeleton >
622std::vector< Index > get_indexes_
623 (const std::vector< typename Skeleton::Id_Type >& ids, Resource_Manager& rman, bool get_attic_idxs = false)
6251337147 q std::vector< Index > result;
6271337147 q Random_File< typename Skeleton::Id_Type, Index > current(rman.get_transaction()->random_index
6281337147 q (current_skeleton_file_properties< Skeleton >()));
6291337147 q for (typename std::vector< typename Skeleton::Id_Type >::const_iterator
630401741147 q it = ids.begin(); it != ids.end(); ++it)
631400404142 q result.push_back(current.get(it->val()));
6331337147 q std::sort(result.begin(), result.end());
6341337147 q result.erase(std::unique(result.begin(), result.end()), result.end());
6361337147 q if (rman.get_desired_timestamp() != NOW || get_attic_idxs)
6371266102 q {
6381266102 q Random_File< typename Skeleton::Id_Type, Index > attic_random(rman.get_transaction()->random_index
6391266102 q (attic_skeleton_file_properties< Skeleton >()));
6401266102 q std::vector< typename Skeleton::Id_Type > idx_list_ids;
6411266102 q for (typename std::vector< typename Skeleton::Id_Type >::const_iterator
642377309102 q it = ids.begin(); it != ids.end(); ++it)
64337604397 q {
64437604397 q if (attic_random.get(it->val()).val() == 0)
64531745976 q ;
6465858463 q else if (attic_random.get(it->val()) == 0xff)
647263427 q idx_list_ids.push_back(it->val());
6485595056 q else
6495595056 q result.push_back(attic_random.get(it->val()));
65037604397 q }
6521266102 q Block_Backend< typename Skeleton::Id_Type, Index > idx_list_db
6531266102 q (rman.get_transaction()->data_index(attic_idx_list_properties< Skeleton >()));
6541266102 q for (typename Block_Backend< typename Skeleton::Id_Type, Index >::Discrete_Iterator
6551266102 q it(idx_list_db.discrete_begin(idx_list_ids.begin(), idx_list_ids.end()));
6566872102 q !(it == idx_list_db.discrete_end()); ++it)
657560627 q result.push_back(it.object());
6591266102 q std::sort(result.begin(), result.end());
6601266102 q result.erase(std::unique(result.begin(), result.end()), result.end());
6611266102 q }
6631337147 q return result;
667#endif