Skip to content

Commit

Permalink
Use partial_sort
Browse files Browse the repository at this point in the history
  • Loading branch information
ymd-stella committed May 1, 2024
1 parent f34e502 commit f3b741f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/stella_vslam/module/local_map_updater.cc
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ auto local_map_updater::count_num_shared_lms(
for (auto& it : keyfrm_to_num_shared_lms) {
num_shared_lms_and_keyfrm.emplace_back(it.second, it.first);
}
std::sort(num_shared_lms_and_keyfrm.begin(), num_shared_lms_and_keyfrm.end(),
greater_number_and_id_object_pairs<unsigned int, data::keyframe>());
constexpr int margin = 5; // Keep a little more than max_num_local_keyfrms_, as keyframes may be deleted.
if (num_shared_lms_and_keyfrm.size() > max_num_local_keyfrms_ + margin) {
std::partial_sort(num_shared_lms_and_keyfrm.begin(),
num_shared_lms_and_keyfrm.begin() + max_num_local_keyfrms_ + margin,
num_shared_lms_and_keyfrm.end(),
greater_number_and_id_object_pairs<unsigned int, data::keyframe>());
}
else {
std::sort(num_shared_lms_and_keyfrm.begin(),
num_shared_lms_and_keyfrm.end(),
greater_number_and_id_object_pairs<unsigned int, data::keyframe>());
}

return num_shared_lms_and_keyfrm;
}
Expand Down

0 comments on commit f3b741f

Please sign in to comment.