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

make index type NonZeroUsize #42

Open
GallagherCommaJack opened this issue May 3, 2020 · 4 comments
Open

make index type NonZeroUsize #42

GallagherCommaJack opened this issue May 3, 2020 · 4 comments

Comments

@GallagherCommaJack
Copy link

It'd be nice to be able to have an Option<Key> which didn't take up more space than Key in memory.

@hawkw
Copy link
Owner

hawkw commented May 3, 2020

We could do this — it might be useful for the tracing-subscriber use-case, as well, where we're currently adding 1 to all indices because 0 is reserved.

However, 0 is a valid slab index. If we did this, we would either end up wasting one slot on thread 0's slab, or need to do some munging of indices ourselves to avoid that. This may be worth it, however.

@inanna-malick
Copy link

Would it be reasonable to add an associated Key type to the Config trait, with the default being usize to allow for custom configs that use std::num::NonZeroUsize instead?

@hawkw
Copy link
Owner

hawkw commented Jul 6, 2020

@inanna-malick hmm, in theory, that could work! Could be worth experimenting with.

@inanna-malick
Copy link

I have a sketch of what it might look like here - it's not quite complete (I don't quite understand everything that's going on around key generation & what would be required to skip 0 there) but it shows the approximate scope of the changes https://github.com/inanna-malick/sharded-slab/tree/associated-key-type

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

No branches or pull requests

3 participants