Skip to content

miaan15/slot-map

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

cmake -B build
cmake --build build

Running Tests

ctest --test-dir build
# or
./build/slot_map_test

Usage

#include "slot_map.cpp"

slot_map<int> 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) {
    // ...
}

About

Slot Map Implementation - C++17 header-only

Topics

Resources

License

Stars

Watchers

Forks

Contributors