Skip to content

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

Closed
mpdn opened this issue Jan 16, 2015 · 4 comments
Closed

HashSet should have a get function #21234

mpdn opened this issue Jan 16, 2015 · 4 comments
Labels
A-collections Area: `std::collections`

Comments

@mpdn
Copy link
Contributor

mpdn commented Jan 16, 2015

I think HashSet should have a get function like HashMap 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 a get function then I could use a HashSet<Arc<Chunk>>, but since it does not, I instead have to use a HashMap<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 for HashMap.

@apasel422
Copy link
Contributor

cc @gankro

@Gankra
Copy link
Contributor

Gankra commented Jan 16, 2015

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
http://discuss.rust-lang.org/t/maps-sets-and-the-value-of-keys/532
rust-lang/rfcs#216

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.

@kmcallister kmcallister added A-libs A-collections Area: `std::collections` labels Jan 16, 2015
@tbu-
Copy link
Contributor

tbu- commented Jan 17, 2015

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.

@steveklabnik
Copy link
Member

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-collections Area: `std::collections`
Projects
None yet
Development

No branches or pull requests

6 participants