slotmap icon indicating copy to clipboard operation
slotmap copied to clipboard

Add `into_dense()` and `get_dense_index()`

Open PROMETHIA-27 opened this issue 2 years ago • 3 comments

I'm working on a project right now where I'd like to temporarily construct a dense slot map, use it for a while, then convert all my keys to indices and the slotmap into a vec to remove indirection for use. While this could be done manually with drain or other existing API, it would be much more efficient to be able to reuse the internal logic to destruct the slotmap for the inner value vec and perform get() calls and return the index instead of the value at that index. I figured someone else might want this API extension.

Also, the random changes outside of .get_dense_index() and .into_dense() are from cargo fmt automatically running. I can undo those if you'd like.

PROMETHIA-27 avatar Sep 30 '22 01:09 PROMETHIA-27

Hey, pretty soon I'll start working on slotmap 2.0 which will demystify keys in general (making them more clearly as an index + version instead of the current agnosticism). By then I'll also make sure to add a method for the dense vector to access the values as a slice, and turn a slotmap into a pair of keys/values vecs.

But I don't think there will be another version before slotmap 2.0 that could include this PR. I'll leave it open for now though so I won't forget for 2.0.

orlp avatar Sep 30 '22 15:09 orlp

Sounds good! Is there an estimate for how long it'll be til 2.0? If not that's ok, I already have my patch in place. Just don't want to forget to update when it's ready.

PROMETHIA-27 avatar Sep 30 '22 16:09 PROMETHIA-27

No estimate yet, sorry.

orlp avatar Sep 30 '22 16:09 orlp