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

HashSet should have a get function #691

Closed
steveklabnik opened this issue Jan 21, 2015 · 5 comments
Closed

HashSet should have a get function #691

steveklabnik opened this issue Jan 21, 2015 · 5 comments

Comments

@steveklabnik
Copy link
Member

Issue by Noctune
Friday Jan 16, 2015 at 13:10 GMT

For earlier discussion, see rust-lang/rust#21234

This issue was labelled with: A-collections, A-libs in the Rust repository


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.

@fuchsnj
Copy link

fuchsnj commented Feb 23, 2015

I would love to see this feature also. It is necessary for object canonicalization.

@sfackler
Copy link
Member

I have this on the maps and sets in rust-phf since the &'static version of the key is useful for interning and other things: http://sfackler.github.io/rust-phf/doc/phf/struct.Set.html#method.get_key

@apasel422
Copy link
Contributor

I think this was covered by #1194.

@apasel422
Copy link
Contributor

@steveklabnik Do you think this can be closed?

@mbrubeck
Copy link
Contributor

Implemented in rust-lang/rust#28043.

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

Successfully merging a pull request may close this issue.

5 participants