Skip to content

Commit

Permalink
merge the functions sortResultByTime and sortResultByTimeActualSorting
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark-Niemeyer authored and jarkenau committed Dec 15, 2023
1 parent aec342d commit c23a2b5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 33 deletions.
11 changes: 2 additions & 9 deletions seerep_srv/seerep_core/include/seerep_core/core_dataset.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,15 +300,8 @@ class CoreDataset
*/
std::vector<boost::uuids::uuid>
sortResultByTime(std::optional<std::vector<seerep_core_msgs::AabbTimeIdPair>>& timetree_result,
std::set<boost::uuids::uuid> intersectionResult);
/**
* @brief does the actual sorting for the sortResultByTime method
*
* @param sortingVector the data to be sorted
* @return std::vector<boost::uuids::uuid> sorted vector of result uuids
*/
std::vector<boost::uuids::uuid>
sortResultByTimeActualSorting(std::vector<std::pair<int64_t, boost::uuids::uuid>>& sortingVector);
std::optional<std::set<boost::uuids::uuid>> intersectionResult = std::nullopt);

/**
* @brief intersects a vector of sets pairwise recursively until one intersection set remains
* @param vectorOfSets the vector of sets to be intersected
Expand Down
36 changes: 12 additions & 24 deletions seerep_srv/seerep_core/src/core_dataset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -417,37 +417,31 @@ CoreDataset::intersectQueryResults(std::optional<std::vector<seerep_core_msgs::A
"the query";
}
}
else
{
return std::vector(intersectionResult.begin(), intersectionResult.end());
}

return std::vector(intersectionResult.begin(), intersectionResult.end());
}

std::vector<boost::uuids::uuid>
CoreDataset::sortResultByTime(std::optional<std::vector<seerep_core_msgs::AabbTimeIdPair>>& timetree_result,
std::set<boost::uuids::uuid> intersectionResult)
std::optional<std::set<boost::uuids::uuid>> intersectionResult)
{
std::vector<std::pair<int64_t, boost::uuids::uuid>> sortingVector;
for (auto it = std::make_move_iterator(timetree_result.value().begin()),
end = std::make_move_iterator(timetree_result.value().end());
it != end; ++it)
{
if (intersectionResult.find(it->second) != intersectionResult.end())
if (!intersectionResult.has_value() ||
intersectionResult.value().find(it->second) != intersectionResult.value().end())
{
sortingVector.push_back(std::make_pair(boost::geometry::get<0>(it->first.min_corner()), it->second));
}
}
return sortResultByTimeActualSorting(sortingVector);
}

std::vector<boost::uuids::uuid>
CoreDataset::sortResultByTimeActualSorting(std::vector<std::pair<int64_t, boost::uuids::uuid>>& sortingVector)
{
std::sort(sortingVector.begin(), sortingVector.end());
std::vector<boost::uuids::uuid> sortedResults;
sortedResults.reserve(sortingVector.size());
for (auto x : sortingVector)
{
std::cout << x.first << std::endl;
sortedResults.push_back(x.second);
}
return sortedResults;
Expand Down Expand Up @@ -489,31 +483,25 @@ std::vector<boost::uuids::uuid>
CoreDataset::getAllDatasetUuids(std::shared_ptr<seerep_core::CoreDataset::DatatypeSpecifics> datatypeSpecifics,
bool sortByTime)
{
std::vector<seerep_core_msgs::AabbTimeIdPair> allIdsFromTimeTree = std::vector<seerep_core_msgs::AabbTimeIdPair>();
std::optional<std::vector<seerep_core_msgs::AabbTimeIdPair>> allIdsFromTimeTree =
std::vector<seerep_core_msgs::AabbTimeIdPair>();
seerep_core_msgs::AabbTime aabbtime(seerep_core_msgs::TimePoint(((int64_t)std::numeric_limits<uint32_t>::min() << 32 |
((uint64_t)std::numeric_limits<uint32_t>::min()))),
seerep_core_msgs::TimePoint(((int64_t)std::numeric_limits<int32_t>::max()) << 32 |
((uint64_t)std::numeric_limits<uint32_t>::max())));

datatypeSpecifics->timetree.query(boost::geometry::index::intersects(aabbtime),
std::back_inserter(allIdsFromTimeTree));
std::back_inserter(allIdsFromTimeTree.value()));

if (sortByTime)
{
std::vector<std::pair<int64_t, boost::uuids::uuid>> sortingVector;
for (auto it = std::make_move_iterator(allIdsFromTimeTree.begin()),
end = std::make_move_iterator(allIdsFromTimeTree.end());
it != end; ++it)
{
sortingVector.push_back(std::make_pair(boost::geometry::get<0>(it->first.min_corner()), it->second));
}
return sortResultByTimeActualSorting(sortingVector);
return sortResultByTime(allIdsFromTimeTree);
}
else
{
std::vector<boost::uuids::uuid> allIds;
for (auto it = std::make_move_iterator(allIdsFromTimeTree.begin()),
end = std::make_move_iterator(allIdsFromTimeTree.end());
for (auto it = std::make_move_iterator(allIdsFromTimeTree.value().begin()),
end = std::make_move_iterator(allIdsFromTimeTree.value().end());
it != end; ++it)
{
allIds.push_back(std::move(it->second));
Expand Down

0 comments on commit c23a2b5

Please sign in to comment.