SoA

Structure of Arrays

This type constructor turns a structure with any number of fields into a structure with (conceptually) the same number of arrays with minimal overhead (basically two pointers). Even though the implementation uses low-level tricks like pointer-arithmetic, the interface is completely type-safe.

The representation in memory is roughly this: storage = [ [ Fields!T[0], .. ] ... [ Fields!T[$ - 1] .. ] ] (storage is a single memory allocation)

Original at https://gist.github.com/PetarKirov/a074073a12482e761a5e88eec559e5a8

Constructors

this
this(size_t newLength)

Creates a structure of arrays instance with newLength elements.

Members

Aliases

opDollar
alias opDollar = length
Undocumented in source.

Functions

availableCapacity
size_t availableCapacity()

Returns the number of elements that can be inserted without allocation.

capacity
size_t capacity()

Returns the current capacity - the current length rounded up to a power of two. This assumption allows us to save on having a separate field.

empty
bool empty()

Returns true iff no elements are present.

insertBack
void insertBack(Args args)

Given an argument of type T or argument sequence of type Fields!T, inserts the fields of T at the back of the container.

length
size_t length()

Returns the number of inserted elements.

opDispatch
auto opDispatch()

Returns the array corresponding to the instances of field.

opIndex
auto opIndex(size_t idx)
Undocumented in source. Be warned that the author may not have intended to support it.
toString
void toString(Writer sink)
Undocumented in source. Be warned that the author may not have intended to support it.

Variables

fieldIndex
enum size_t fieldIndex(string fieldName);

Given a field name, returns its index. Callable at compile-time.

Meta