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

Differences from linked-hash-map? #9

Closed
dtolnay opened this issue Nov 14, 2016 · 2 comments
Closed

Differences from linked-hash-map? #9

dtolnay opened this issue Nov 14, 2016 · 2 comments
Labels

Comments

@dtolnay
Copy link
Contributor

dtolnay commented Nov 14, 2016

What are the reasons someone would prefer one or the other?

They both provide the same basic guarantees: iteration order matches insertion order and "constant time" for various operations.

From the readme it sounds like OrderMap lookups are faster than LinkedHashMap (OrderMap is faster than HashMap, while LinkedHashMap uses HashMap internally). Also linked-hash-map uses gobs of unsafe code.

Would you recommend OrderMap in all cases over LinkedHashMap or are there some disadvantages?

@bluss
Copy link
Member

bluss commented Nov 14, 2016

OrderMap's iteration is probably a mountain faster. About lookups we don't claim to be faster than HashMap in general. It benches a bit faster for smaller cases, but we also know that OrderMap has a greater indirection / cache hit cost to lookups.

Very important to note: OrderMap's guarantee is an order that is consistent, not dependent on key hashes, and depends on the sequence of inserts and removals. It does not keep strict insertion order like linked hashmap. It's also unsuitable to use as an LRU cache, and it can not "pop front" and so on.

I recommend OrderMap when it's a good fit, but it's quite different from the linked hashmap.

@bluss bluss added the question label Nov 14, 2016
@dtolnay
Copy link
Contributor Author

dtolnay commented Nov 14, 2016

Thanks for the explanation and for weighing in on our yaml-rust discussion.

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

2 participants