https://github.com/miaan15/slot-map
Slot Map Implementation - C++17 header-only
https://github.com/miaan15/slot-map
cpp data-structures header-only slot-map
Last synced: 10 days ago
JSON representation
Slot Map Implementation - C++17 header-only
- Host: GitHub
- URL: https://github.com/miaan15/slot-map
- Owner: miaan15
- License: mit
- Created: 2026-03-04T09:30:13.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-03-04T10:28:24.000Z (4 months ago)
- Last Synced: 2026-06-11T16:38:48.381Z (10 days ago)
- Topics: cpp, data-structures, header-only, slot-map
- Language: C++
- Homepage:
- Size: 19.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Slot Map
A header-only C++17 implementation of the **slot map** data structure.
Widely used in ECS
## Features
- O(1) insertion, deletion, and lookup
- Stable key handles that remain valid across insertions and deletions by generational safety
- Contiguous data storage for cache-friendly iteration
- Standard convention implementation
## Building
```bash
cmake -B build
cmake --build build
```
## Running Tests
```bash
ctest --test-dir build
# or
./build/slot_map_test
```
## Usage
```cpp
#include "slot_map.cpp"
slot_map sm;
// Insert elements
auto k1 = sm.insert(42);
auto k2 = sm.emplace(100);
// Access by key
int value = sm[k1]; // 42
sm[k2] = 200;
// Check if key is valid
if (sm.contains(k1)) {
// ...
}
// Find element
auto it = sm.find(k1);
if (it != sm.end()) {
// *it == 42
}
// Erase by key or iterator
sm.erase(k1);
// Iterate over all elements (contiguous storage)
for (auto &val : sm) {
// ...
}
```