-
Notifications
You must be signed in to change notification settings - Fork 70
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
provide Keydata.get_idx_version #43
Conversation
In particular, the idx is unique at any one instant, and "small". There are possible use cases where this is a useful property and will save the caller the trouble of maintaining a separate set of ids. It seems churlish to hide this, particularly given as it's even printed by the Debug impl. Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
I'm sorry, I really, explicitly do not want to do this. |
That's a shame. I found a way to do what I needed using only things which seem to me to be part of
|
Hi. I really like this crate. Thanks.
I had one small issue that I think would be best addressed by adding a new getter on KeyData. My MR leaks the abstraction a bit more (about as much as the Debug impl does) but in my situation it would be quite useful. To motivate, I will explain:
I'm writing a game system. Players in a game may come and go but there will be few at any one time. I'm already using SlotMap for my record of the players.
I want to have something like a "player number" visible to the users: there's a player nickname but in one circumstance (a graphical representation) I really want something much terser. A small integer would be ideal. (Player 1 etc.)
Slotmap has that internally of course. But right now it's hidden. My options are 1. make a new data structure very similar to SlotMap 2. abuse KeyData.as_ffi 3. Add a method to get the slot index.
It seems to me that 3 is the right answer so here is my MR. I hope you like it. I wasn't quite sure what name and precise API you would like but this one seems OK to me. Returning the version as well is potentially a tiny bit wasteful and/or irrelevant, but it does make the doc exposition a lot easier.
I have noticed that DenseSlotMap doesn't seem to use index 0. I didn't add a guarantee that the index would be nonzero for a real entry. Should I add that to the doc?