r/cpp • • 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!

The benchmarks results can be found here.

33 Upvotes

21 comments sorted by

View all comments

Show parent comment

1

u/sporacid Mar 27 '26

I've just merged a new PR with optimizations. Among those, there is a static storage which is completely lock-free, no mutexes involved, if you're interested :)