r/cpp • u/sporacid • Mar 21 '26
Slot map implementation for C++20
I've just finished submitting the initial version of my slot map implementation, based on this post. A slot map is a data structure that provides stable and versioned keys to stored values. Inserting into the map creates and return a unique key, which stays valid until the slot is explicitly freed.
I hope someone will find this useful :)
https://github.com/sporacid/slot-map
EDIT: As suggested by some of you, I've added benchmarks to compare to plf::colony. As i did those benchmarks, I had to work on a bunch of optomizations to compete, and I've introduce a static storage that has a fixed number of slots, and I kept the original dynamic storage with a fixed number of blocks, but the blcoks are allocated as needed. Let me know what you think!
View all comments
Show parent comment
1
u/sporacid Mar 27 '26
I'll see if I can find some time to add other benchmarks to represent other type of workload.
I'm surprised it bloats your compile time, I would be very interested as well to understand why, especially the part where it seems to scale with map capacity. Theoretically, it's not doing much at compile time, only figuring some optimal block size and bitset depth. Most functions are constexpr, but I would assume most slot map workloads to be exclusively resolved at runtime. I've made it constexpr just because I could. Let me know if you find anything.