Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about implement gtsam::KeyValueMap with hashable container? #1703

Open
demul opened this issue Jan 2, 2024 · 4 comments
Open

How about implement gtsam::KeyValueMap with hashable container? #1703

demul opened this issue Jan 2, 2024 · 4 comments

Comments

@demul
Copy link

demul commented Jan 2, 2024

Feature

It seems that gtsam::KeyValueMap is implemented based on boost::ptr_map.
And boost::ptr_map is implemented based on std::map (https://www.boost.org/doc/libs/1_81_0/libs/ptr_container/doc/ptr_map.html)
std::map is implemented with red-black tree.
So the time complexity of gtsam::KeyValueMap::find is O(logN).
So, gtsam::Value::exists takes O(logN).

Motivation

I want to make gtsam::Value::exists faster.

Pitch

The time complexity of gtsam::Value::exists becomes constant time.

Alternatives

How about using std::unordered_map instead of boost::ptr_map?

@ProfFan
Copy link
Collaborator

ProfFan commented Jan 2, 2024

I think last time we discussed it's because we can't break API in 4.x

@varunagrawal
Copy link
Collaborator

KeyValueMap uses std::map in the current develop, so I'm not sure what the issue is asking for.

@demul
Copy link
Author

demul commented Jan 3, 2024

@varunagrawal
std::map is implemented with red-black tree, so KeyValueMap::find takes O(logN).
I thought replacing std::map with std::unordered_map will be better because std::unordered_map is a hashable container, so KeyValueMap::find will takes O(1).

@ProfFan
Thank you, so maybe this feature request is going to be addressed on next version(5.X) API?
And would you give me the link for the discussion before?

@ProfFan
Copy link
Collaborator

ProfFan commented Jan 19, 2024

@varunagrawal std::map is implemented with red-black tree, so KeyValueMap::find takes O(logN). I thought replacing std::map with std::unordered_map will be better because std::unordered_map is a hashable container, so KeyValueMap::find will takes O(1).

@ProfFan Thank you, so maybe this feature request is going to be addressed on next version(5.X) API? And would you give me the link for the discussion before?

You can search in the issues, it's long long time ago. Actually what you can even do is just make a fork replacing Value to be a simple map, and then make a PR :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants