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

overpass_api/data/collect_items.h

354 of 397 instrumented lines run by the suite (89.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>
29172826390201 qinline uint64 timestamp_of(const Attic< Node_Skeleton >& skel) { return skel.timestamp; }
30968805170 qinline uint64 timestamp_of(const Attic< Way_Skeleton >& skel) { return skel.timestamp; }
3115081892 qinline uint64 timestamp_of(const Attic< Relation_Skeleton >& skel) { return skel.timestamp; }
33410734113202 qinline uint64 timestamp_of(const Node_Skeleton& skel) { return NOW; }
342051285166 qinline uint64 timestamp_of(const Way_Skeleton& skel) { return NOW; }
3517180589 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)
45626316202 q{
46327892380202 q while (!(it == end) && it.index() == index)
47327266064202 q {
48327266064202 q ++count;
49327266064202 q if (timestamp < timestamp_of(it.object()))
50239985072202 q {
51239985072202 q timestamp_by_id.push_back(std::make_pair(it.object().id, timestamp_of(it.object())));
52239985072202 q if (predicate.match(it.object()))
5316309367201 q result.push_back(it.object());
54239985072202 q }
55327266064202 q ++it;
56327266064202 q }
57626316202 q}
60class Statement;
63class Health_Guard
65public:
6690214587 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)
7087704539 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:
8136775648 q Request_Context(const Statement* stmt_, Resource_Manager& rman_) : stmt(stmt_), rman(rman_) {}
8390214587 q Health_Guard get_health_guard() { return Health_Guard(stmt, rman); }
84118602645 q uint64 get_desired_timestamp() const { return rman.get_desired_timestamp(); }
85 File_Blocks_Index_Base* data_index(const File_Properties* file_properties)
8615540638 q { return rman.get_transaction()->data_index(file_properties); }
87 Random_File_Index* random_index(const File_Properties* file_properties)
883624 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)
104309300219 q{
105309300219 q std::vector< Object > skels;
106309300219 q std::vector< Attic< typename Object::Delta > > deltas;
107309300219 q std::vector< std::pair< typename Object::Id_Type, uint64 > > local_timestamp_by_id;
10919016508219 q while (!(current_it == current_end) && current_it.index() == idx)
11018707208196 q {
11118707208196 q timestamp_by_id.push_back(std::make_pair(current_it.object().id, NOW));
11218707208196 q local_timestamp_by_id.push_back(std::make_pair(current_it.object().id, NOW));
11318707208196 q skels.push_back(current_it.object());
11418707208196 q ++current_it;
11518707208196 q }
11794506093219 q while (!(attic_it == attic_end) && attic_it.index() == idx)
11894196793219 q {
11994196793219 q if (timestamp < attic_it.object().timestamp)
12026107957216 q {
12126107957216 q timestamp_by_id.push_back(std::make_pair(attic_it.object().id, attic_it.object().timestamp));
12226107957216 q local_timestamp_by_id.push_back(std::make_pair(attic_it.object().id, attic_it.object().timestamp));
12326107957216 q deltas.push_back(attic_it.object());
12426107957216 q }
12594196793219 q ++attic_it;
12694196793219 q }
128309300219 q std::vector< const Attic< typename Object::Delta >* > delta_refs;
129309300219 q delta_refs.reserve(deltas.size());
130309300219 q for (typename std::vector< Attic< typename Object::Delta > >::const_iterator it = deltas.begin();
13126417257219 q it != deltas.end(); ++it)
13226107957216 q delta_refs.push_back(&*it);
134309300219 q std::sort(skels.begin(), skels.end());
135309300219 q std::sort(delta_refs.begin(), delta_refs.end(), Delta_Ref_Comparator< Attic< typename Object::Delta > >());
136309300219 q std::sort(local_timestamp_by_id.begin(), local_timestamp_by_id.end());
138309300219 q std::vector< Attic< Object > > attics;
139309300219 q typename std::vector< Object >::const_iterator skels_it = skels.begin();
140309300219 q Object reference;
141309300219 q for (typename std::vector< const Attic< typename Object::Delta >* >::const_iterator it = delta_refs.begin();
14226417257219 q it != delta_refs.end(); ++it)
14326107957216 q {
14426107957216 q if (!(reference.id == (*it)->id))
1456118318216 q {
14620119402216 q while (skels_it != skels.end() && skels_it->id < (*it)->id)
14714001084194 q ++skels_it;
1486118318216 q if (skels_it != skels.end() && skels_it->id == (*it)->id)
1494691099195 q reference = *skels_it;
1501427219212 q else
1511427219212 q reference = Object();
1526118318216 q }
15326107957216 q try
15426107957216 q {
15526107957216 q Attic< Object > attic_obj = Attic< Object >((*it)->expand(reference), (*it)->timestamp);
15626107957216 q if (attic_obj.id.val() != 0)
15726107957216 q {
15826107957216 q reference = attic_obj;
15926107957216 q typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::const_iterator
16026107957216 q tit = std::lower_bound(local_timestamp_by_id.begin(), local_timestamp_by_id.end(),
16126107957216 q std::make_pair((*it)->id, 0ull));
16226107957216 q if (tit != local_timestamp_by_id.end() && tit->first == (*it)->id && tit->second == (*it)->timestamp)
1636118318216 q attics.push_back(attic_obj);
16426107957216 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 }
17326107957216 q }
17426107957216 q catch (const std::exception& e)
17526107957216 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 }
18126107957216 q }
1836427618219 q for (typename std::vector< Attic< Object > >::const_iterator it = attics.begin(); it != attics.end(); ++it)
1846118318216 q {
1856118318216 q if (predicate.match(*it))
1861119623197 q attic_result.push_back(*it);
1876118318216 q }
18919016508219 q for (typename std::vector< Object >::const_iterator it = skels.begin(); it != skels.end(); ++it)
19018707208196 q {
19118707208196 q if (predicate.match(*it))
1922223090191 q result.push_back(*it);
19318707208196 q }
194309300219 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)
2011244916266 q{
2021244916266 q typename std::vector< Object >::iterator target_it = result.begin();
2031244916266 q for (typename std::vector< Object >::iterator it2 = result.begin();
20420896996266 q it2 != result.end(); ++it2)
20519652080256 q {
20619652080256 q typename std::vector< std::pair< typename Object::Id_Type, uint64 > >::const_iterator
20719652080256 q tit = std::lower_bound(timestamp_by_id.begin(), timestamp_by_id.end(),
20819652080256 q std::make_pair(it2->id, 0ull));
20919652080256 q if (tit != timestamp_by_id.end() && tit->first == it2->id && tit->second == timestamp_of(*it2))
21016116021256 q {
21116116021256 q *target_it = *it2;
21216116021256 q ++target_it;
21316116021256 q }
21419652080256 q }
2151244916266 q result.erase(target_it, result.end());
2161244916266 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)
2595457209 q uint32 count = 0;
260318615209 q while (!(current_begin == current_end) || !(attic_begin == attic_end))
261313158202 q {
262313158202 q std::vector< std::pair< typename Object::Id_Type, uint64 > > timestamp_by_id;
264313158202 q bool too_much_data = false;
265313158202 q if (++count >= 128*1024)
266200892 q {
267200892 q count = 0;
268200892 q health_guard.check(0, eval_map(result));
269200892 q health_guard.check(0, eval_map(attic_result));
270200892 q }
271313158202 q Index index =
272313158202 q (attic_begin == attic_end ||
273313158202 q (!(current_begin == current_end) && current_begin.index() < attic_begin.index())
274313158202 q ? current_begin.index() : attic_begin.index());
275313158202 q if (too_much_data && cur_idx)
2760 {
2770 *cur_idx = index;
2780 return true;
2790 }
281313158202 q reconstruct_items(
282313158202 q current_begin, current_end, index, predicate, result[index], timestamp_by_id, timestamp, count);
283313158202 q reconstruct_items(
284313158202 q attic_begin, attic_end, index, predicate, attic_result[index], timestamp_by_id, timestamp, count);
286313158202 q std::sort(timestamp_by_id.begin(), timestamp_by_id.end());
288313158202 q filter_items_by_timestamp(timestamp_by_id, result[index]);
289313158202 q filter_items_by_timestamp(timestamp_by_id, attic_result[index]);
291 //check_for_duplicated_objects< Object >(timestamp_by_id, rman);
292313158202 q }
2935457209 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)
305415138 q uint32 count = 0;
306106083138 q while (!(current_begin == current_end) || !(attic_begin == attic_end))
307105668118 q {
308105668118 q std::vector< std::pair< Relation_Skeleton::Id_Type, uint64 > > timestamp_by_id;
310105668118 q bool too_much_data = false;
311105668118 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 }
317105668118 q Index index =
318105668118 q (attic_begin == attic_end ||
319105668118 q (!(current_begin == current_end) && current_begin.index() < attic_begin.index())
320105668118 q ? current_begin.index() : attic_begin.index());
321105668118 q if (too_much_data && cur_idx)
3220 {
3230 *cur_idx = index;
3240 return true;
3250 }
327105668118 q reconstruct_items(health_guard, current_begin, current_end, attic_begin, attic_end, index,
328105668118 q predicate, result[index], attic_result[index], timestamp_by_id, timestamp);
330105668118 q std::sort(timestamp_by_id.begin(), timestamp_by_id.end());
332105668118 q filter_items_by_timestamp(timestamp_by_id, result[index]);
333105668118 q filter_items_by_timestamp(timestamp_by_id, attic_result[index]);
335 //check_for_duplicated_objects< Relation_Skeleton >(timestamp_by_id, rman);
336105668118 q }
337415138 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)
34726322253 q {
34826322253 q current.swap(rhs_current);
34926322253 q attic.swap(rhs_attic);
35026322253 q return *this;
35126322253 q }
353 Timeless& sort()
3545165674 q {
3555165674 q sort_second(current);
3565165674 q sort_second(attic);
3575165674 q return *this;
3585165674 q }
360 Timeless& set_union(const Timeless< Index, Object >& rhs)
36136956 q {
36236956 q indexed_set_union(current, rhs.current);
36336956 q indexed_set_union(attic, rhs.attic);
36436956 q return *this;
36536956 q }
367 template< typename Predicate >
368 Timeless& filter_items(const Predicate& predicate)
3704641 q ::filter_items(predicate, current);
3714641 q ::filter_items(predicate, attic);
3724641 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)
390654203 q uint32 count = 0;
391204286203 q while (!(current_begin == current_end) || !(attic_begin == attic_end))
392203632193 q {
393203632193 q std::vector< std::pair< Way_Skeleton::Id_Type, uint64 > > timestamp_by_id;
395203632193 q bool too_much_data = false;
396203632193 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 }
402203632193 q Index index =
403203632193 q (attic_begin == attic_end ||
404203632193 q (!(current_begin == current_end) && current_begin.index() < attic_begin.index())
405203632193 q ? current_begin.index() : attic_begin.index());
406203632193 q if (too_much_data && cur_idx)
4070 {
4080 *cur_idx = index;
4090 return true;
4100 }
412203632193 q reconstruct_items(health_guard, current_begin, current_end, attic_begin, attic_end, index,
413203632193 q predicate, result[index], attic_result[index], timestamp_by_id, timestamp);
415203632193 q std::sort(timestamp_by_id.begin(), timestamp_by_id.end());
417203632193 q filter_items_by_timestamp(timestamp_by_id, result[index]);
418203632193 q filter_items_by_timestamp(timestamp_by_id, attic_result[index]);
420 //check_for_duplicated_objects< Way_Skeleton >(timestamp_by_id, rman);
421203632193 q }
422654203 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)
4491643265 q Block_Backend< Index, Object, typename Container::const_iterator > current_db(
4501643265 q context.data_index(current_skeleton_file_properties< Object >()));
4511643265 q if (timestamp == NOW)
4533820286173 q for (auto it = current_db.discrete_begin(req.begin(), req.end()); !(it == current_db.discrete_end()); ++it)
4543819586137 q {
4553819586137 q if (predicate.match(it.handle()))
456444597128 q result[it.index()].push_back(it.object());
4573819586137 q }
459943126 q else
461943126 q Block_Backend< Index, Attic< typename Object::Delta >, typename Container::const_iterator > attic_db(
462943126 q context.data_index(attic_skeleton_file_properties< Object >()));
464943126 q collect_items_by_timestamp(context.get_health_guard(),
465943126 q current_db.discrete_begin(req.begin(), req.end()), current_db.discrete_end(),
466943126 q attic_db.discrete_begin(req.begin(), req.end()), attic_db.discrete_end(),
467943126 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)
478575240 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)
48587876519 q{
48687876519 q Timeless< Index, Object > result;
48787876519 q if (ranges.empty() || !predicate.possible())
48881536453 q return result;
4906340384 q Block_Backend< Index, Object > current_db
4916340384 q (context.data_index(current_skeleton_file_properties< Object >()));
4926340384 q if (context.get_desired_timestamp() == NOW)
4931092268 q {
494424552685268 q for (auto it = current_db.range_begin(ranges); !(it == current_db.range_end()); ++it)
495424551593265 q {
496424551593265 q if (predicate.match(it.handle()))
49728889212265 q result.current[it.index()].push_back(it.object());
498424551593265 q }
4991092268 q }
5005248150 q else
5015248150 q {
5025248150 q Block_Backend< Index, Attic< typename Object::Delta > > attic_db
5035248150 q (context.data_index(attic_skeleton_file_properties< Object >()));
5045248150 q collect_items_by_timestamp(context.get_health_guard(),
5055248150 q current_db.range_begin(ranges), current_db.range_end(),
5065248150 q attic_db.range_begin(ranges), attic_db.range_end(),
5075248150 q predicate, (Index*)0, context.get_desired_timestamp(), result.current, result.attic);
5085248150 q }
5096340384 q return result;
51087876519 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)
519939499 q Ranges< Index > shortened = ranges.skip_start(cur_idx);
520939499 q Block_Backend< Index, Object > current_db(
521939499 q context.data_index(current_skeleton_file_properties< Object >()));
523939499 q if (context.get_desired_timestamp() == NOW)
525606333 q uint32 count = 0;
526606333 q bool too_much_data = false;
528478092456333 q for (auto it = current_db.range_begin(shortened); !(it == current_db.range_end()); ++it)
529478091854325 q {
530478091854325 q if (too_much_data && !(cur_idx == it.index()))
53244 q cur_idx = it.index();
53344 q return true;
535478091850325 q if (++count >= 256*1024)
536172586 q {
537172586 q count = 0;
538172586 q too_much_data = context.get_health_guard().check(0, eval_map(result));
539172586 q cur_idx = it.index();
540172586 q }
541478091850325 q if (predicate.match(it.handle()))
54282148883322 q result[it.index()].push_back(it.object());
543478091850325 q }
545602333 q return false;
547333203 q else
549333203 q Block_Backend< Index, Attic< typename Object::Delta > > attic_db(
550333203 q context.data_index(attic_skeleton_file_properties< Object >()));
552333203 q return collect_items_by_timestamp(context.get_health_guard(),
553333203 q current_db.range_begin(shortened), current_db.range_end(),
554333203 q attic_db.range_begin(shortened), attic_db.range_end(),
555333203 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)
5666153 q uint32 count = 0;
5676153 q Block_Backend< Index, Object > db(context.data_index(&file_properties));
5686153 q for (typename Block_Backend< Index, Object >::Flat_Iterator
56942846453 q it(db.flat_begin()); !(it == db.flat_end()); ++it)
57042840353 q {
57142840353 q if (++count >= 256*1024)
5720 {
5730 count = 0;
5740 context.get_health_guard().check(0, eval_map(result));
5750 }
57642840353 q if (predicate.match(it.handle()))
5771347051 q result[it.index()].push_back(it.object());
57842840353 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)
5883018 q Block_Backend< Index, Object > current_db
5893018 q (context.data_index(current_skeleton_file_properties< Object >()));
5913018 q if (context.get_desired_timestamp() == NOW)
5932816 q uint32 count = 0;
594165001216 q for (auto it = current_db.flat_begin(); !(it == current_db.flat_end()); ++it)
595164998416 q {
596164998416 q if (++count >= 256*1024)
5970 {
5980 count = 0;
5990 context.get_health_guard().check(0, eval_map(result));
6000 }
601164998416 q if (predicate.match(it.handle()))
60225839 q result[it.index()].push_back(it.object());
603164998416 q }
60522 q else
60722 q Block_Backend< Index, Attic< typename Object::Delta > > attic_db
60822 q (context.data_index(attic_skeleton_file_properties< Object >()));
61022 q collect_items_by_timestamp(context.get_health_guard(),
61122 q current_db.flat_begin(), current_db.flat_end(),
61222 q attic_db.flat_begin(), attic_db.flat_end(),
61322 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)
6251342211 q std::vector< Index > result;
6271342211 q Random_File< typename Skeleton::Id_Type, Index > current(rman.get_transaction()->random_index
6281342211 q (current_skeleton_file_properties< Skeleton >()));
6291342211 q for (typename std::vector< typename Skeleton::Id_Type >::const_iterator
630858843211 q it = ids.begin(); it != ids.end(); ++it)
631857501202 q result.push_back(current.get(it->val()));
6331342211 q std::sort(result.begin(), result.end());
6341342211 q result.erase(std::unique(result.begin(), result.end()), result.end());
6361342211 q if (rman.get_desired_timestamp() != NOW || get_attic_idxs)
6371217133 q {
6381217133 q Random_File< typename Skeleton::Id_Type, Index > attic_random(rman.get_transaction()->random_index
6391217133 q (attic_skeleton_file_properties< Skeleton >()));
6401217133 q std::vector< typename Skeleton::Id_Type > idx_list_ids;
6411217133 q for (typename std::vector< typename Skeleton::Id_Type >::const_iterator
642810114133 q it = ids.begin(); it != ids.end(); ++it)
643808897124 q {
644808897124 q if (attic_random.get(it->val()).val() == 0)
64548443976 q ;
64632445898 q else if (attic_random.get(it->val()) == 0xff)
6471252730 q idx_list_ids.push_back(it->val());
64831193190 q else
64931193190 q result.push_back(attic_random.get(it->val()));
650808897124 q }
6521217133 q Block_Backend< typename Skeleton::Id_Type, Index > idx_list_db
6531217133 q (rman.get_transaction()->data_index(attic_idx_list_properties< Skeleton >()));
6541217133 q for (typename Block_Backend< typename Skeleton::Id_Type, Index >::Discrete_Iterator
6551217133 q it(idx_list_db.discrete_begin(idx_list_ids.begin(), idx_list_ids.end()));
65621347133 q !(it == idx_list_db.discrete_end()); ++it)
6572013030 q result.push_back(it.object());
6591217133 q std::sort(result.begin(), result.end());
6601217133 q result.erase(std::unique(result.begin(), result.end()), result.end());
6611217133 q }
6631342211 q return result;
667#endif