Skip to content

Bevy's HashSet missing some functionality #2115

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
TheLeonsver1 opened this issue May 5, 2021 · 4 comments
Closed

Bevy's HashSet missing some functionality #2115

TheLeonsver1 opened this issue May 5, 2021 · 4 comments
Labels
C-Bug An unexpected or incorrect behavior C-Dependencies A change to the crates that Bevy depends on

Comments

@TheLeonsver1
Copy link

Bevy version

0.5

Operating system & version

Windows 10.

What you did

tried to initiate a HashSet with with_capactity()

What you expected to happen

A HashSet to be initiated with the wanted capacity.

What actually happened

rustc error https://doc.rust-lang.org/error-index.html#E0599

Additional information

no.

@TheLeonsver1 TheLeonsver1 added C-Bug An unexpected or incorrect behavior S-Needs-Triage This issue needs to be labelled labels May 5, 2021
@TehPers
Copy link
Contributor

TehPers commented May 5, 2021

The standard implementations for HashSet and HashMap implement new() and with_capacity() only for std's RandomState. Since bevy re-exports them with ahash's RandomState, we lose those implementations. This could be worked around by creating an extension trait when working with ahash versions of those data structures.

@alice-i-cecile alice-i-cecile added C-Dependencies A change to the crates that Bevy depends on and removed S-Needs-Triage This issue needs to be labelled labels May 5, 2021
@cart
Copy link
Member

cart commented May 5, 2021

We actually used to have this, but @bjorn3 removed it in #1235 to cut down on compile times. I'll let them respond here with rationale for / against.

@bjorn3
Copy link
Contributor

bjorn3 commented May 6, 2021

It was just a slight improvement if I recall correctly. The majority of the change was in the last commit of that PR. I replaced a HashMap::with_capacity(size) (where with_capacity came from AHashExt) with HashMap::with_capacity_and_hasher(size, Default::default()). The former is more elegant than the later so I guess it is fine to reintroduce AHashExt for just with_capacity. HashMap::new() is not significantly nicer than HashMap::default() so I have a slight preference for not reintroducing AHashExt::new.

@cart
Copy link
Member

cart commented May 6, 2021

Cool cool. Then I think its worth adding it back, as the whole point is to abstract out the hasher. I also agree that we don't need new().

tiagolam added a commit to tiagolam/bevy that referenced this issue Jun 25, 2021
PR bevyengine#1235 had removed the AHashExt trait and respective
`with_capacity()`s implementations, leaving only the less ergonomic
`HashMap::with_capacity_and_hasher(size, Default::default())` option
available.

This re-introduces `AHashExt` and respective `with_capacity()`
implementations to give a more ergonimic way to set a HashMap / HashSet
capacity.

As a note, this has also been discussed and agreed on issue bevyengine#2115, which
this PR addresses.

Fixes bevyengine#2115.

Signed-off-by: Tiago Lam <[email protected]>
tiagolam added a commit to tiagolam/bevy that referenced this issue Jun 25, 2021
PR bevyengine#1235 had removed the AHashExt trait and respective
`with_capacity()`s implementations, leaving only the less ergonomic
`HashMap::with_capacity_and_hasher(size, Default::default())` option
available.

This re-introduces `AHashExt` and respective `with_capacity()`
implementations to give a more ergonomic way to set a HashMap / HashSet
capacity.

As a note, this has also been discussed and agreed on issue bevyengine#2115, which
this PR addresses.

Fixes bevyengine#2115.

Signed-off-by: Tiago Lam <[email protected]>
tiagolam added a commit to tiagolam/bevy that referenced this issue Jun 25, 2021
PR bevyengine#1235 had removed the `AHashExt` trait and respective
`with_capacity()`s implementations, leaving only the less ergonomic
`HashMap::with_capacity_and_hasher(size, Default::default())` option
available.

This re-introduces `AHashExt` and respective `with_capacity()`
implementations to give a more ergonomic way to set a `HashMap` /
`HashSet` capacity.

As a note, this has also been discussed and agreed on issue bevyengine#2115, which
this PR addresses.

Fixes bevyengine#2115.

Signed-off-by: Tiago Lam <[email protected]>
@bors bors bot closed this as completed in 1bc34b4 Jun 26, 2021
ostwilkens pushed a commit to ostwilkens/bevy that referenced this issue Jul 27, 2021
# Objective
Re-introduce `AHashExt` and respective `with_capacity()` implementations to give a more ergonomic way to set a `HashMap` / `HashSet` capacity.

As a note, this has also been discussed and agreed on issue bevyengine#2115, which this PR addresses (leaving `new()` out of the `AHashExt` trait).

Fixes bevyengine#2115.

## Solution
PR bevyengine#1235 had removed the `AHashExt` trait and respective `with_capacity()`s implementations, leaving only the less ergonomic `HashMap::with_capacity_and_hasher(size, Default::default())` option available.

This re-introduces `AHashExt` and respective `with_capacity()` implementations to give a more ergonomic way to set a `HashMap` / `HashSet` capacity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Bug An unexpected or incorrect behavior C-Dependencies A change to the crates that Bevy depends on
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants