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

What is complexity of iteration over indexmap? #227

Closed
AngelicosPhosphoros opened this issue May 20, 2022 · 4 comments
Closed

What is complexity of iteration over indexmap? #227

AngelicosPhosphoros opened this issue May 20, 2022 · 4 comments
Labels

Comments

@AngelicosPhosphoros
Copy link

I recently discovered that std::collections::HashMap iterator iterates over all items in map for O(capacity), not O(length).
Indexmap probably can have iteration for O(length) using index based access. What is current complexity?

@cuviper
Copy link
Member

cuviper commented May 20, 2022

The map iterators are based on the underlying vector of items, and that's contiguous, no deletion tombstones or anything like that. So yes, they should all be O(length).

That's also true for the simple set iterators. The multi-set ones like difference or union do add hash lookups, but that's still O(1) average, so I guess the same complexity overall.

@bluss
Copy link
Member

bluss commented May 24, 2022

This is basically described in the readme https://github.com/bluss/indexmap#performance but the readme is old and needs updating, so sure, it's hard to know what to trust.

@AngelicosPhosphoros
Copy link
Author

AngelicosPhosphoros commented May 25, 2022

Well, it says that iteration is performant, it doesn't say exact complexity :)

@bluss
Copy link
Member

bluss commented May 25, 2022

Hm, it says the key-value pairs are stored in a Vec and the iteration is over them, densely, that's why it's basically describing it.

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

No branches or pull requests

3 participants