MCPcopy Create free account
hub / github.com/TUC-ProAut/libRSF / getTimeCloseTo

Method getTimeCloseTo

include/DataSet.h:399–466  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

397 }
398
399 bool getTimeCloseTo(const KeyType &ID, const double Timestamp, double& TimestampClose) const
400 {
401 /** catch non-existing key */
402 if (!this->checkID(ID))
403 {
404 PRINT_ERROR("Key does not exist: ", ID);
405 return false;
406 }
407 /** catch empty container */
408 if(this->countElements(ID) == 0)
409 {
410 PRINT_ERROR("Container is empty for key: ", ID);
411 return false;
412 }
413
414 /** find closest iterators */
415 const auto ItLow = _DataStreams.at(ID).lower_bound(Timestamp);
416 const auto ItHigh = _DataStreams.at(ID).upper_bound(Timestamp);
417
418 /** case 1: element is above all */
419 if(ItLow == _DataStreams.at(ID).end())
420 {
421 TimestampClose = std::prev(ItLow)->first;
422 }
423 else if (ItHigh == _DataStreams.at(ID).begin())
424 {
425 /** case 2: element is below all */
426 TimestampClose = ItLow->first;
427 }
428 else
429 {
430 /** general case: element is somewhere between */
431 double TimeLow;
432 double TimeHigh;
433
434 /** safely get time below lower bound */
435 if(ItLow == _DataStreams.at(ID).begin())
436 {
437 TimeLow = ItLow->first;
438 }
439 else
440 {
441 TimeLow = std::prev(ItLow)->first;
442 }
443
444 /** safely get time at upper bound */
445 if(ItHigh == _DataStreams.at(ID).end())
446 {
447 TimeHigh = std::prev(ItHigh)->first;
448 }
449 else
450 {
451 TimeHigh = ItHigh->first;
452 }
453
454 /** compare times */
455 if (abs(TimeLow - Timestamp) < abs(TimeHigh - Timestamp))
456 {

Callers

nothing calls this directly

Calls 6

checkIDMethod · 0.95
countElementsMethod · 0.95
lower_boundMethod · 0.80
upper_boundMethod · 0.80
endMethod · 0.80
beginMethod · 0.80

Tested by

no test coverage detected