-
Notifications
You must be signed in to change notification settings - Fork 13.3k
HashSet should have a get function #21234
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
Comments
cc @gankro |
So the reason HashSet doesn't provide such an API is because HashMap doesn't give any way to get keys. The reason HashMap doesn't give keys is because this is basically the standard interface for Maps across many programming languages. I sympathize with those of you who have "interesting keys", and would be totally willing to add in support for looking at keys, but we're slamming towards 1.0 and I don't have a strong enough opinion on this to champion it in earnest. See also: #20601 CC @frankmcsherry @stepancheg @eddyb If one of you wants to collect up the usecases, look at performance numbers, and write up a coherent RFC for this, I would be more than willing to help out and push it in the appropriate faces. Note that some Maps and Sets do not necessarily contain the keys they index by. e.g. BitvSet does not store the integers you perform lookups with. Same for possible TrieMap designs. This is important for providing a coherent Map and Set API. |
https://www.reddit.com/r/rust/comments/2snuup/is_there_a_way_to_get_my_keys_back/ Here it's really important to get the keys back, because the key is a buffer that would need to get reallocated otherwise. |
I'm pulling a massive triage effort to get us ready for 1.0. As part of this, I'm moving stuff that's wishlist-like to the RFCs repo, as that's where major new things should get discussed/prioritized. This issue has been moved to the RFCs repo: rust-lang/rfcs#691 |
I think
HashSet
should have aget
function likeHashMap
has, as equality does not necessarily mean that two elements are identical.The reason I think this is necessary is that I'm trying to create a voxel world (think Minecraft) that is split into 3D chunks. Many of these chunks are identical (a lot of it is just air, for example), so it would make sense to reuse the a chunk in several places. When a new chunk is generated, the hash of the chunk is looked up in a collection to see if there is an already identical chunk and if there is, then use that one.
If
HashSet
had aget
function then I could use aHashSet<Arc<Chunk>>
, but since it does not, I instead have to use aHashMap<Arc<Chunk>, Arc<Chunk>>
where the key and value is always the same which does not seem totally logical and downright impossible if it were a non-cloneable key.Likewise, it may be an idea to implement some sort of
get_key_value
that would return a key value pair forHashMap
.The text was updated successfully, but these errors were encountered: