DynamicArray

Array type with deterministic control of memory. The memory allocated for the array is reclaimed as soon as possible; there is no reliance on the garbage collector. Array uses malloc, realloc and free for managing its own memory.

Use std.bitmanip.BitArray for array container storing boolean values.

TODO optimize by making members templates. 0.579s before, eval-dwim: 0.67s

TODO Add OutputRange.writer support as https://github.com/burner/StringBuffer/blob/master/source/stringbuffer.d#L45

TODO Use std.traits.areCopyCompatibleArrays

@safe
struct DynamicArray (
T
alias Allocator = null
CapacityType = size_t
) if (
!is(Unqual!T == bool) &&
(
is(CapacityType == ulong) ||
is(CapacityType == uint)
)
) {}

Constructors

this
this(T value)

Construct from uncopyable element value.

this
this(U value)

Construct from copyable element value.

this
this(U[] values)

Construct from the element(s) of the dynamic array values.

this
this(U[n] values)
this(R values)

Construct from the n number of element(s) in the static array values.

Destructor

~this
~this()

Destruct.

Postblit

this(this)
this(this)

No default copying.

Members

Aliases

opDollar
alias opDollar = length
Undocumented in source.
put
alias put = insertBack

Insert the elements elements into the end of the array.

Enums

isElementAssignable
eponymoustemplate isElementAssignable(U)

Is true if U can be assign to the element type T of this.

Functions

back
inout(T) back()

Get reference to back element.

backPop
T backPop()

Pop back element and return it.

clear
void clear()

Empty.

front
inout(T) front()

Get reference to front element.

frontPop
T frontPop()

Move element at front.

insertBack
void insertBack(T value)

Insert unmoveable value into the end of the array.

insertBack
void insertBack(U[] values)

Insert the elements values into the end of the array.

insertBack
void insertBack(R elements)

Insert the elements elements into the end of the array.

insertBack1
void insertBack1(T value)

Insert value into the end of the array.

insertBackMove
void insertBackMove(T value)

Move value into the end of the array.

moveAt
T moveAt(size_t index)

Move element at index to return.

opEquals
bool opEquals(typeof(this) rhs)
bool opEquals(U[] rhs)

Comparison for equality.

opIndex
inout(T) opIndex(size_t i)

Index support.

opIndexAssign
T opIndexAssign(U value, size_t i)

Index assignment support.

opOpAssign
void opOpAssign(T value)
void opOpAssign(U[] values)
void opOpAssign(R values)

Forwards to insertBack(values).

opOpAssign
void opOpAssign(typeof(this) values)
Undocumented in source. Be warned that the author may not have intended to support it.
opSlice
inout(T)[] opSlice(size_t i, size_t j)
inout(T)[] opSlice()

Slice support.

opSliceAssign
T[] opSliceAssign(U value)
T[] opSliceAssign(U value, size_t i, size_t j)

Slice assignment support.

popAt
void popAt(size_t index)

Pop element at index.

popBack
void popBack()

Remove last value fromm the end of the array.

popBackN
void popBackN(size_t n)

Rmove n last values from the end of the array.

ptr
inout(T)* ptr()

Unsafe access to pointer.

reserve
void reserve(size_t minimumCapacity)

Ensures sufficient capacity to accommodate for minimumCapacity number of elements. If minimumCapacity < capacity, this method does nothing.

toHash
hash_t toHash()

Calculate D associative array (AA) key hash.

toString
void toString(void delegate(scope const(char)[]) sink)

Construct a string representation of this at sink.

Properties

capacity
size_t capacity [@property getter]

Get capacity.

dup
DynamicArray!(Unqual!T, Allocator, CapacityType) dup [@property getter]
empty
bool empty [@property getter]

Check if empty.

length
size_t length [@property getter]

Get length.

length
size_t length [@property setter]

Set length to newLength.

Static functions

emplaceWithCopiedElements
typeof(this) emplaceWithCopiedElements(typeof(this)* thatPtr, const(T)[] elements)

Emplace thatPtr with elements copied from elements.

emplaceWithMovedElements
typeof(this) emplaceWithMovedElements(typeof(this)* thatPtr, T[] elements)

Emplace thatPtr with elements moved from elements.

withCapacity
typeof(this) withCapacity(size_t initialCapacity)
withElements
typeof(this) withElements(T[] elements)
Undocumented in source. Be warned that the author may not have intended to support it.
withElementsOfRange_untested
typeof(this) withElementsOfRange_untested(R values)

Construct from the elements values.

withLength
typeof(this) withLength(size_t initialLength)
withLengthElementValue
typeof(this) withLengthElementValue(size_t length, T elementValue)

Construct using - initial length length, - and value of all elements elementValue.

See Also

Meta