Skip to content

A high performance associative container with persistent keys.

License

Notifications You must be signed in to change notification settings

Games-by-Mason/SlotMap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SlotMap

A high performance associative container. Returns a unique persistent key for each added item.

Useful for managing objects with runtime known lifetimes, such as entities in a video game, since keys are never "dangling."

Persistent keys are implemented as indices paired with bit generation counters. Saturated generation counters are not reused, which means that after creating and destroying capacity * @intFromEnum(Generation.invalid) entries the slot map will run out of unique keys and return error.Overflow on put.

Inspired by SergeyMakeev/slot_map.

Example

var slots: SlotMap(u8, []const u8) = try .init(gpa, 100);
defer slots.deinit(gpa);

const key = slots.put("hello, world!");
const value = slots.get(key).?;

slots.remove(key);
assert(!slots.exists(key));

About

A high performance associative container with persistent keys.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages