A set of fixed-sized C++ storage arrays with various features.
This header-only library provides the following fixed-sized data structures:
A reduced "array and a counter" fixed sized data structure for writing data to once and then copying. Trivially copyable. Nothing very fancy.
An array built around std::aligned_storage
for a given type. Abstracts the process of creating and destroying elements with placement new in otherwise uninitialized data. Does not keep track of which cells are occupied with what, and as such does not provide RAII safety. Serves as the backbone for the following structures.
A fixed sized, pared down implementation of the Slot Map data structure, which provides the following properties:
-
O(1) emplacement and deletion*.
-
O(1) lookup.
-
Data is stored contiguously but unordered and can be iterated as such.
-
Access is done via versioned keys to avoid dangling references.
-
Does not perform or require default element construction for unused slots.
-
Elements are automatically cleaned up upon deletion of the structure, similar to an
std::vector
.
(* - On deletion, some iteration may be done to clean up the free slot list.)
A deconstruction of the slot_array
structure, intended for storing random access resources safely.
-
O(1) emplacement and deletion.
-
O(1) lookup.
-
Data is not stored contiguously and can not be natively iterated.
-
Access is done via versioned keys to avoid dangling references.
-
Unlike
slot_array
, no elements are moved or rearranged upon deletion (good for large storage). -
Does not perform or require default element construction for unused slots.
-
Elements are automatically cleaned up upon deletion of the structure, similar to an
std::vector
.
An ordered static/fixed vector of sorts. Provides contiguous data in-place.
-
O(1) emplacement and deletion from end.
-
O(1) lookup.
-
Data is contiguous and ordered and can be natively iterated.
-
Access is done via index. This structure does not use keys or versioning.
-
Does not perform or require default element construction for unused slots.
-
Elements are automatically cleaned up upon deletion of the structure, similar to an
std::vector
.
A generic generational pointer key used for slot_array
and keyed_array
. Used to prevent dangling references. Can store a few bytes of "metadata" internally as a result of some spare room from alignment. The purpose of this data is left to the user.
This is a header-only library with no nonstandard dependencies. Simply use the files provided in the include/
directory as desired.
TBD.
This repository uses Catch2 for testing. You can learn more about Catch2 here. Test coverage is reasonably acceptable but could be improved for corner cases.
This repository is tested with VS2017 and VS2019.
You can download Premake 5 here.
premake5 vs2017
===============================================================================
All tests passed (6214 assertions in 28 test cases)
This repository is tested with GCC 8.3 and Clang-8 under Ubuntu. Older compiler versions may have issues with the use of some language features (such as std::launder
).
$ git clone https://github.com/recatek/fixed_storage_arrays
You can download Premake 5 here.
$ ./premake5 gmake
$ make config=release
$ ./build/bin/release/tests
===============================================================================
All tests passed (6214 assertions in 28 test cases)
MIT. Go nuts. Don't blame me.