![]() |
ezEngine Release 26.9
|
Implementation of a dynamically growing array with in-place storage and small memory overhead. More...
#include <SmallArray.h>
Inherited by ezSmallArray< ezArrayPtr< ezUInt8 >, 4 >, ezSmallArray< AllocationInfo, 16 >, ezSmallArray< ezUInt32, 8 >, ezSmallArray< GraphInstance, 2 >, ezSmallArray< ezAnimGraphPinDataBoneWeights, 4 >, ezSmallArray< ezAnimGraphPinDataLocalTransforms, 4 >, ezSmallArray< ezAnimGraphPinDataModelTransforms, 2 >, ezSmallArray< FinalCurveValue, 4 >, ezSmallArray< ezAnimGraphCustomCurveData, 2 >, ezSmallArray< ezColorGradientColorCP, 8 >, ezSmallArray< ezColorGradientAlphaCP, 8 >, ezSmallArray< ezColorGradientIntensityCP, 8 >, ezSmallArray< ezUInt8, 8 >, ezSmallArray< ezGALVertexAttribute, 8 >, ezSmallArray< ezComponentHandle, 1 >, ezSmallArray< ezEnum< ezExpression::RegisterType >, 8, ezStaticsAllocatorWrapper >, ezSmallArray< ezExpressionAST::Input *, 8 >, ezSmallArray< ezExpressionAST::Output *, 8 >, ezSmallArray< ezExpressionAST::Node *, 4 >, ezSmallArray< const ezExpression::FunctionDesc *, 1 >, ezSmallArray< ezExpressionAST::Node *, 8 >, ezSmallArray< TempData, 2 >, ezSmallArray< ezGALVertexAttribute, 2 >, ezSmallArray< ezTextureDependency, 2 >, ezSmallArray< ezBufferDependency, 2 >, ezSmallArray< ezTextureDependency, 4 >, ezSmallArray< ezBufferDependency, 4 >, ezSmallArray< ezJoltMeshMapping, 1 >, ezSmallArray< ezLensFlareElement, 1 >, ezSmallArray< ezTypedResourceHandle, 2 >, ezSmallArray< ezMeshDecalDescription, 2 >, ezSmallArray< ezGenericId, 2 >, ezSmallArray< ezTypedResourceHandle, 4 >, ezSmallArray< ezVec2Template, 4 >, ezSmallArray< ezParticleAttractorData, 1 >, ezSmallArray< ezSimdVec4f, 16, ezAlignedAllocatorWrapper >, ezSmallArray< Binding, 4 >, ezSmallArray< ezParticleEmitter *, 2 >, ezSmallArray< ezParticleInitializer *, 6 >, ezSmallArray< ezParticleBehavior *, 6 >, ezSmallArray< ezParticleFinalizer *, 2 >, ezSmallArray< ezParticleType *, 2 >, ezSmallArray< StreamInfo, 16 >, ezSmallArray< ezUInt8, 4 >, ezSmallArray< ezProcVertexColorOutputDesc, 1 >, ezSmallArray< ezSharedPtr< const ezProcGenInternal::VertexColorOutput >, 1 >, ezSmallArray< ezAbstractMessageHandler *, 1, ezStaticsAllocatorWrapper >, ezSmallArray< const ezRTTI *, 7, ezStaticsAllocatorWrapper >, ezSmallArray< ezGALVertexAttribute, 16 >, ezSmallArray< ezGALVertexAttribute, 3 >, ezSmallArray< EventSender, 1 >, ezSmallArray< ezUniquePtr< ezAbstractFunctionProperty >, NumInplaceFunctions >, ezSmallArray< ezUniquePtr< ezAbstractMessageHandler >, NumInplaceFunctions >, ezSmallArray< const ezAbstractFunctionProperty *, NumInplaceFunctions >, ezSmallArray< ezAbstractMessageHandler *, NumInplaceFunctions >, ezSmallArray< ezGameObjectHandle, 1 >, ezSmallArray< ezSplineMeshPart, 1 >, ezSmallArray< TransitionContext, 2 >, ezSmallArray< ezUInt32, 2 >, ezSmallArray< ezStateMachineState *, 2 >, ezSmallArray< ezStateMachineTransition *, 2 >, ezSmallArray< ezTagSetBlockStorage, 1, ezDefaultAllocatorWrapper >, ezSmallArray< ezTagSetBlockStorage, 1, BlockStorageAllocator >, ezSmallArray< ezUInt32, 1 >, ezSmallArray< ezVisualScriptCompiler::ExecInput, 2 >, ezSmallArray< ezVisualScriptCompiler::ExecOutput, 2 >, ezSmallArray< ezVisualScriptCompiler::DataInput, 7 >, ezSmallArray< ezVisualScriptCompiler::DataOutput, 4 >, ezSmallArray< ezUInt16, 4 >, ezSmallArray< ezVisualScriptDataDescription::DataOffset, 4 >, ezSmallArray< ezVisualScriptDataDescription::DataOffset, 2 >, ezSmallArray< ezVisualScriptNodeRegistry::PinDesc, 4 >, ezSmallArray< const ezAbstractProperty *, 1 >, ezSmallArray< ezHashedString, 1 >, and ezSmallArray< T, Size, AllocatorWrapper >.
Public Types | |
| using | value_type = T |
| using | const_reference = const T & |
| using | const_iterator = const T * |
| using | const_reverse_iterator = const_reverse_pointer_iterator< T > |
| using | iterator = T * |
| using | reverse_iterator = reverse_pointer_iterator< T > |
Public Member Functions | |
| EZ_DECLARE_MEM_RELOCATABLE_TYPE_CONDITIONAL (T) | |
| ezSmallArrayBase (const ezSmallArrayBase< T, Size > &other, ezAllocator *pAllocator) | |
| ezSmallArrayBase (const ezArrayPtr< const T > &other, ezAllocator *pAllocator) | |
| ezSmallArrayBase (ezSmallArrayBase< T, Size > &&other, ezAllocator *pAllocator) | |
| void | operator= (const ezSmallArrayBase< T, Size > &rhs)=delete |
| void | operator= (ezSmallArrayBase< T, Size > &&rhs)=delete |
| void | CopyFrom (const ezArrayPtr< const T > &other, ezAllocator *pAllocator) |
| Copies the data from some other array into this one. | |
| void | MoveFrom (ezSmallArrayBase< T, Size > &&other, ezAllocator *pAllocator) |
| Moves the data from some other array into this one. | |
| operator ezArrayPtr< const T > () const | |
| Conversion to const ezArrayPtr. | |
| operator ezArrayPtr< T > () | |
| Conversion to ezArrayPtr. | |
| bool | operator== (const ezSmallArrayBase< T, Size > &rhs) const |
| Compares this array to another contiguous array type. | |
| EZ_ADD_DEFAULT_OPERATOR_NOTEQUAL (const ezSmallArrayBase< T, Size > &) | |
| bool | operator< (const ezSmallArrayBase< T, Size > &rhs) const |
| Compares this array to another contiguous array type. | |
| bool | operator< (const ezArrayPtr< const T > &rhs) const |
| const T & | operator[] (ezUInt32 uiIndex) const |
| Returns the element at the given index. Does bounds checks in debug builds. | |
| T & | operator[] (ezUInt32 uiIndex) |
| Returns the element at the given index. Does bounds checks in debug builds. | |
| void | SetCount (ezUInt16 uiCount, ezAllocator *pAllocator) |
| Resizes the array to have exactly uiCount elements. Default constructs extra elements if the array is grown. | |
| void | SetCount (ezUInt16 uiCount, const T &fillValue, ezAllocator *pAllocator) |
| Resizes the array to have exactly uiCount elements. Constructs all new elements by copying the FillValue. | |
| template<typename = void> | |
| void | SetCountUninitialized (ezUInt16 uiCount, ezAllocator *pAllocator) |
| Resizes the array to have exactly uiCount elements. Extra elements might be uninitialized. | |
| void | EnsureCount (ezUInt16 uiCount, ezAllocator *pAllocator) |
| Ensures the container has at least uiCount elements. Ie. calls SetCount() if the container has fewer elements, does nothing otherwise. | |
| ezUInt32 | GetCount () const |
| Returns the number of active elements in the array. | |
| bool | IsEmpty () const |
| Returns true, if the array does not contain any elements. | |
| void | Clear () |
| Clears the array. | |
| bool | Contains (const T &value) const |
| Checks whether the given value can be found in the array. O(n) complexity. | |
| void | Insert (const T &value, ezUInt32 uiIndex, ezAllocator *pAllocator) |
| Inserts value at index by shifting all following elements. | |
| void | Insert (T &&value, ezUInt32 uiIndex, ezAllocator *pAllocator) |
| Inserts value at index by shifting all following elements. | |
| bool | RemoveAndCopy (const T &value) |
| Removes the first occurrence of value and fills the gap by shifting all following elements. | |
| bool | RemoveAndSwap (const T &value) |
| Removes the first occurrence of value and fills the gap by swapping in the last element. | |
| void | RemoveAtAndCopy (ezUInt32 uiIndex, ezUInt16 uiNumElements=1) |
| Removes the element at index and fills the gap by shifting all following elements. | |
| void | RemoveAtAndSwap (ezUInt32 uiIndex, ezUInt16 uiNumElements=1) |
| Removes the element at index and fills the gap by swapping in the last element. | |
| ezUInt32 | IndexOf (const T &value, ezUInt32 uiStartIndex=0) const |
| Searches for the first occurrence of the given value and returns its index or ezInvalidIndex if not found. | |
| ezUInt32 | LastIndexOf (const T &value, ezUInt32 uiStartIndex=ezSmallInvalidIndex) const |
| Searches for the last occurrence of the given value and returns its index or ezInvalidIndex if not found. | |
| T & | ExpandAndGetRef (ezAllocator *pAllocator) |
| Grows the array by one element and returns a reference to the newly created element. | |
| void | PushBack (const T &value, ezAllocator *pAllocator) |
| Pushes value at the end of the array. | |
| void | PushBack (T &&value, ezAllocator *pAllocator) |
| Pushes value at the end of the array. | |
| void | PushBackUnchecked (const T &value) |
| Pushes value at the end of the array. Does NOT ensure capacity. | |
| void | PushBackUnchecked (T &&value) |
| Pushes value at the end of the array. Does NOT ensure capacity. | |
| void | PushBackRange (const ezArrayPtr< const T > &range, ezAllocator *pAllocator) |
| Pushes all elements in range at the end of the array. Increases the capacity if necessary. | |
| void | PopBack (ezUInt32 uiCountToRemove=1) |
| Removes count elements from the end of the array. | |
| T & | PeekBack () |
| Returns the last element of the array. | |
| const T & | PeekBack () const |
| Returns the last element of the array. | |
| template<typename Comparer > | |
| void | Sort (const Comparer &comparer) |
| Sort with explicit comparer. | |
| void | Sort () |
| Sort with default comparer. | |
| T * | GetData () |
| Returns a pointer to the array data, or nullptr if the array is empty. | |
| const T * | GetData () const |
| Returns a pointer to the array data, or nullptr if the array is empty. | |
| ezArrayPtr< T > | GetArrayPtr () |
| Returns an array pointer to the array data, or an empty array pointer if the array is empty. | |
| ezArrayPtr< const T > | GetArrayPtr () const |
| Returns an array pointer to the array data, or an empty array pointer if the array is empty. | |
| ezArrayPtr< typename ezArrayPtr< T >::ByteType > | GetByteArrayPtr () |
| Returns a byte array pointer to the array data, or an empty array pointer if the array is empty. | |
| ezArrayPtr< typename ezArrayPtr< const T >::ByteType > | GetByteArrayPtr () const |
| Returns a byte array pointer to the array data, or an empty array pointer if the array is empty. | |
| void | Reserve (ezUInt16 uiCapacity, ezAllocator *pAllocator) |
| Expands the array so it can at least store the given capacity. | |
| void | Compact (ezAllocator *pAllocator) |
| Tries to compact the array to avoid wasting memory. The resulting capacity is at least 'GetCount' (no elements get removed). Will deallocate all data, if the array is empty. | |
| ezUInt32 | GetCapacity () const |
| Returns the reserved number of elements that the array can hold without reallocating. | |
| ezUInt64 | GetHeapMemoryUsage () const |
| Returns the amount of bytes that are currently allocated on the heap. | |
| template<typename U > | |
| const U & | GetUserData () const |
| template<typename U > | |
| U & | GetUserData () |
| template<typename U > | |
| EZ_ALWAYS_INLINE const U & | GetUserData () const |
| template<typename U > | |
| EZ_ALWAYS_INLINE U & | GetUserData () |
Protected Types | |
| enum | { CAPACITY_ALIGNMENT = 4 } |
Protected Member Functions | |
| void | SetCapacity (ezUInt16 uiCapacity, ezAllocator *pAllocator) |
| T * | GetElementsPtr () |
| const T * | GetElementsPtr () const |
Protected Attributes | ||
| ezUInt16 | m_uiCount = 0 | |
| ezUInt16 | m_uiCapacity = Size | |
| ezUInt32 | m_uiUserData = 0 | |
| union { | ||
| struct alignas { | ||
| ezUInt8 m_StaticData [Size *sizeof(T)] | ||
| } | ||
| T * m_pElements = nullptr | ||
| }; | ||
Implementation of a dynamically growing array with in-place storage and small memory overhead.
Contrary to ezDynamicArray and ezHybridArray, the ezSmallArray only uses a 16-bit index, so it can only hold 64K items (65535). It is meant for use cases, where the maximum required size is low, but the size of the container itself should also be as small as possible.
Best-case performance for the PushBack operation is in O(1) if the ezSmallArray does not need to be expanded. In the worst case, PushBack is O(n). Look-up is guaranteed to always be O(1).