A C++ data structure that behaves like a map with integer keys but guarantees Θ(1) worst-case time for all major operations, including insertion, deletion, access, and key reuse.
- Constant-time insert, remove, access, and size
- Auto key management via a KeyPool (no gaps)
- Dynamic resizing using background copying
- Optional overflow queue support
- Full iteration and named instances
| Operation | Time |
|---|---|
| insert | Θ(1) |
| remove | Θ(1) |
| at(key) | Θ(1) |
| hasKey(key) | Θ(1) |
| size | Θ(1) |
| clear | Θ(1) |
| contains(val) | Θ(n) |
📌 See EXPLANATIONS.md for details on every method.
Use KeyArray when:
- You need fast access and insert by integer keys
- You want to avoid STL
unordered_mapormapoverhead - You want safe, sparse key usage with constant-time recycling
KeyArray.hpp— Main class with full functionalityKeyArrayBase.hpp— Core logic for fixed-sized versionKeyPool.hpp— Lightweight internal key recyclerREADME.md— Overview and usageEXPLANATIONS.md— Method-by-method complexity
KeyArray<std::string> users("UserList");
int id = users.insert("Alice");
users.remove(id);Created with ❤️ by [Your Name]