A Vec<T>
-like collection which guarantees stable indices and features O(1)
deletion of elements at the cost of wasting some memory. Please refer to the
the documentation for more information.
This crate is still young, but the API won't change a lot. Everything should already work as intended, but it's not extensively tested yet. If you're working on mission-critical software, please don't use this library. Otherwise feel free to do so!
slab
?A few weeks after writing the intial version of this crate, I found the crate slab
which does pretty much the same as this crate (and has way more downloads). Despite being very similar, there are a few differences which might be important for you:
slab
reuses keys of deleted entries, while stable-vec
does not automatically.slab
does a bit more management internally to quickly know which keys to reuse and where to insert. This might incur a tiny bit of overhead. Most notably: each entry in the underlying Vec
in slab
is at least sizeof::<usize>() + 1
bytes large. If you're storing small elements, this might be a significant memory usage overhead.slab
uses only one Vec
and each element has the information whether or not it is vacant or occupied. stable-vec
(currently) uses one Vec<T>
and a BitVec
. Be aware of the different performance characteristics. (stable-vec
might switch to Vec<Option<T>>
in the future, though).slab
is designed like an associative map, while stable-vec
's API is designed more like a Vec
with additional guarantees. Both crates are probably mostly used as low level building blogs for other things; stable-vec
might be a tiny bit more low level.Yes please! In particular, you could work on these things:
unsafe
code is completely fine. It's not a lot of unsafe
code and I think it's fine, but it would be nice to have certainty.I'm glad to do some mentoring for anyone interested in contributing.
Licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.