Skip to content

Commit

Permalink
fix: use shared_ptr & unordered_map, minimize hashmap search
Browse files Browse the repository at this point in the history
  • Loading branch information
hiikariri committed Dec 28, 2023
1 parent 7863a50 commit 077dc07
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/akushon/action/model/action.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class Action
bool is_using_spline() const;
void generate_splines();

std::map<uint8_t, keisan::SmoothSpline *> joint_splines;
std::unordered_map<uint8_t, std::shared_ptr<keisan::SmoothSpline>> joint_splines;

private:
std::string name;
Expand Down
8 changes: 4 additions & 4 deletions src/akushon/action/model/action.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ void Action::generate_splines()
joint_splines.clear();
for (auto pose : poses) {
for (auto & joint : pose.get_joints()) {
uint8_t joint_id = joint.get_id();
if (joint_splines.find(joint_id) == joint_splines.end()) {
joint_splines[joint_id] = std::make_shared<keisan::SmoothSpline>().get();
const auto it = joint_splines.find(joint.get_id());
if (it == joint_splines.end()) {
joint_splines.emplace(joint.get_id(), std::make_shared<keisan::SmoothSpline>());
}
joint_splines[joint_id]->add_point(joint.get_position(), pose.get_time());
it->second->add_point(joint.get_position(), pose.get_time());
}
}
}
Expand Down

0 comments on commit 077dc07

Please sign in to comment.