🟨 Generic containers (SC::Vector, SC::SmallVector, SC::Array etc.)
Containers is a library holding some commonly used generic data structures.
Class | Description |
---|---|
SC::Vector | A contiguous sequence of heap allocated elements. |
SC::Array | A contiguous sequence of elements kept inside its inline storage. |
SC::SmallVector | A Vector that can hold up to N elements inline and > N on heap. |
SC::VectorMap | A map holding VectorMapItem key-value pairs in an unsorted Vector. |
SC::VectorSet | A set built on an unsorted Vector, ensuring no item duplication. |
SC::ArenaMap | A sparse vector keeping objects at a stable memory location. |
SC::IntrusiveDoubleLinkedList | An Intrusive Double Linked List. |
🟨 MVP
SC::Vector, SC::Array and friends should be reasonably stable.
Generic data structures are a fundamental building blocks for almost every application.
These are some of commonly used ones for common tasks, and the library will grow adding what's needed.
SC::Vector is the king of all generic containers for this library, being in many case the main backend storage for other containers.
SC::Array mimics all methods of SC::Vector but it's guaranteed never to allocate on heap.
All methods are designed to fail with a [[nodiscard]]
return value when the container is full.
SC::SmallVector is the middle ground between SC::Array and SC::Vector.
It's a vector with inline storage for N
elements, deriving from SC::Vector and it's designed to be passed everywhere a reference to SC::Vector is needed. This allows the caller to get rid of temporary heap allocations if an estimate of the space required is already known or if it's possible providing a reasonable default.
If this estimation is wrong, heap allocation will happen.
A contiguous sequence of heap allocated elements.
T | Type of single vector element |
All methods of SC::Vector that can fail, return a [[nodiscard]]
bool
(example SC::Vector::push_back).
Assignment and Copy / move construct operators will just assert as they can't return a failure code.
memcpy
is used to optimize copies when T
is a memcpy-able object.
Example:
A contiguous sequence of elements kept inside its inline storage.
T | Type of single element of the Array |
N | Number of elements contained inside this Array inline storage |
SC::Array is like a SC::Vector but it will only allow up to N
elements in the array, using inline storage, without resorting to heap allocation.
Trying to push or insert more than N elements will fail.
Only up to SC::Array::size elements are valid (and N
- size()
are initialized).
Example:
A Vector that can hold up to N
elements inline and > N
on heap.
T | Type of single vector element |
N | Number of elements kept inline to avoid heap allocation |
SC::SmallVector is like SC::Vector but it will do heap allocation once more than N
elements are needed.
When the size()
becomes less than N
the container will switch back using memory coming from inline storage.
Example:
A map holding VectorMapItem key-value pairs in an unsorted Vector.
Key | Type of the key (must support == comparison) |
Value | Value type associated with Key |
Container | Container used for the Map |
Example:
A set built on an unsorted Vector, ensuring no item duplication.
Value | The contained value |
Container | The underlying container used |
Example:
A sparse vector keeping objects at a stable memory location.
T | Type of items kept in this Arena |
SC::ArenaMap is a container used to keep objects memory location stable.
Internally it hold sparse objects inside of a SC::Vector and for this reason it can only be SC::ArenaMap::resize-d when it's empty.
Objects can be inserted up to the SC::ArenaMap::size and insertion returns handle keys allowing to retrieve the inserted object in constant time.
Example:
An Intrusive Double Linked List.
T | The Type being linked. It must declare two pointers to itself named next and prev . |
This is an useful data structure when we want to delegate the allocation strategy to caller.
Both Async and Process use this data structure to store requests.
SC::SegmentItems
is the class representing a variable and contiguous slice of objects backing both SC::Vector and SC::Array. SC::SegmentHeaderBase
holding size and capacity of the segment followed by the actual elements.SC::SegmentHeaderBase
is aligned to uint64_t
.SC::SegmentHeader
= SC::SegmentHeaderBase
so the SC::SegmentHeader
size is 8 bytes.🟩 Usable Features:
HashMap<T>
Map<K, V>
🟦 Complete Features:
💡 Unplanned Features: