Struct NativeArraySparseSet
An adapter collection for external data arrays that allows constant-time insertion, deletion, and lookup by handle, as well as array-like iteration.
Implements
Namespace: GDX.Collections
Syntax
public struct NativeArraySparseSet : IDisposable
Constructors
| Improve this Doc View SourceNativeArraySparseSet(Int32, Allocator)
Create a NativeArraySparseSet with an initialCapacity
.
Declaration
public NativeArraySparseSet(int initialCapacity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | initialCapacity | The initial capacity of the sparse and dense int arrays. |
Unity.Collections.Allocator | allocator | The Unity.Collections.Allocator type to use. |
NativeArraySparseSet(Int32, Allocator, out NativeArray<UInt64>)
Create a NativeArraySparseSet with an initialCapacity
.
Declaration
public NativeArraySparseSet(int initialCapacity, Allocator allocator, out NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | initialCapacity | The initial capacity of the sparse and dense int arrays. |
Unity.Collections.Allocator | allocator | The Unity.Collections.Allocator type to use. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
Fields
| Improve this Doc View SourceCount
How many indices are being used currently?
Declaration
public int Count
Field Value
Type | Description |
---|---|
System.Int32 |
DenseArray
Holds references to the sparse array for swapping indices.
Declaration
public NativeArray<int> DenseArray
Field Value
Type | Description |
---|---|
Unity.Collections.NativeArray<System.Int32> |
FreeIndex
The first free (currently unused) index in the sparse array.
Declaration
public int FreeIndex
Field Value
Type | Description |
---|---|
System.Int32 |
SparseArray
Holds references to dense array indices.
Declaration
public NativeArray<int> SparseArray
Field Value
Type | Description |
---|---|
Unity.Collections.NativeArray<System.Int32> |
Remarks
Its own indices are claimed and freed via a free-list.
Methods
| Improve this Doc View SourceAddUnchecked(out Int32, out Int32)
Adds a sparse/dense index pair to the set without checking if the set needs to expand.
Declaration
public void AddUnchecked(out int sparseIndex, out int denseIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndex | The sparse index allocated. |
System.Int32 | denseIndex | The dense index allocated. |
AddUnchecked(out Int32, out Int32, NativeArray<UInt64>, out UInt64)
Adds a sparse/dense index pair to the set without checking if the set needs to expand.
Declaration
public void AddUnchecked(out int sparseIndex, out int denseIndex, NativeArray<ulong> versionArray, out ulong version)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndex | The sparse index allocated. |
System.Int32 | denseIndex | The dense index allocated. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | The array containing the version number to check against. |
System.UInt64 | version | Enables detection of use-after-free errors when using the sparse index as a reference. |
AddWithExpandCheck(Int32, out Int32, out Int32, Allocator)
Adds a sparse/dense index pair to the set and expands the arrays if necessary.
Declaration
public bool AddWithExpandCheck(int expandBy, out int sparseIndex, out int denseIndex, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expandBy | How many indices to expand by. |
System.Int32 | sparseIndex | The sparse index allocated. |
System.Int32 | denseIndex | The dense index allocated. |
Unity.Collections.Allocator | allocator | The Unity.Collections.Allocator type to use. |
Returns
Type | Description |
---|---|
System.Boolean | True if the index pool expanded. |
AddWithExpandCheck(Int32, out Int32, out Int32, Allocator, ref NativeArray<UInt64>)
Adds a sparse/dense index pair to the set and expands the arrays if necessary.
Declaration
public bool AddWithExpandCheck(int expandBy, out int sparseIndex, out int denseIndex, Allocator allocator, ref NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | expandBy | How many indices to expand by. |
System.Int32 | sparseIndex | The sparse index allocated. |
System.Int32 | denseIndex | The dense index allocated. |
Unity.Collections.Allocator | allocator | The Unity.Collections.Allocator type to use. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
Returns
Type | Description |
---|---|
System.Boolean | True if the index pool expanded. |
Clear()
Clear the dense and sparse arrays.
Declaration
public void Clear()
Clear(NativeArray<UInt64>)
Clear the dense and sparse arrays.
Declaration
public void Clear(NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
ClearWithVersionArrayReset(NativeArray<UInt64>)
Clear the dense and sparse arrays and reset the version array. Note: Only clear the version array if you are sure there are no outstanding dependencies on version numbers.
Declaration
public void ClearWithVersionArrayReset(NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
Dispose()
Declaration
public void Dispose()
Expand(Int32, Allocator)
Reallocate the dense and sparse arrays with additional capacity.
Declaration
public void Expand(int extraCapacity, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | extraCapacity | How many indices to expand the dense and sparse arrays by. |
Unity.Collections.Allocator | allocator | The Unity.Collections.Allocator type to use. |
Expand(Int32, Allocator, ref NativeArray<UInt64>)
Reallocate the dense and sparse arrays with additional capacity.
Declaration
public void Expand(int extraCapacity, Allocator allocator, ref NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | extraCapacity | How many indices to expand the dense and sparse arrays by. |
Unity.Collections.Allocator | allocator | Which Unity memory allocator to use with the backing array. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
GetDenseIndexUnchecked(Int32)
Gets the value of the sparse array at the given index without any data validation.
Declaration
public int GetDenseIndexUnchecked(int sparseIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndex | The index to check in the sparse array. |
Returns
Type | Description |
---|---|
System.Int32 | The dense index at the given sparse index. |
GetDenseIndexWithBoundsAndVersionCheck(Int32, UInt64, NativeArray<UInt64>)
Gets the value of the sparse array at the given index, or -1 if the given sparse index is invalid..
Declaration
public int GetDenseIndexWithBoundsAndVersionCheck(int sparseIndex, ulong version, NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndex | The index in the sparse array to check against. |
System.UInt64 | version | The version number associated with the sparse index. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | The array containing the version number to check against. |
Returns
Type | Description |
---|---|
System.Int32 | The dense index pointed to by the current sparse index, or -1 if invalid. |
GetDenseIndexWithBoundsCheck(Int32)
Gets the value of the sparse array at the given index, or -1 if the dense and sparse indices don't point to each other or if the dense index is outside the dense bounds.
Declaration
public int GetDenseIndexWithBoundsCheck(int sparseIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndex | The index in the sparse array to check against. |
Returns
Type | Description |
---|---|
System.Int32 | The dense index pointed to by the current sparse index, or -1 if invalid. |
GetDenseIndexWithVersionCheck(Int32, UInt64, NativeArray<UInt64>)
Gets the value of the sparse array at the given index, or -1 if the version number does not match.
Declaration
public int GetDenseIndexWithVersionCheck(int sparseIndex, ulong version, NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndex | The index in the sparse array to check against. |
System.UInt64 | version | The version number associated with the sparse index. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | The array containing the version number to check against. |
Returns
Type | Description |
---|---|
System.Int32 | The dense index pointed to by the current sparse index, or -1 if invalid. |
RemoveUnchecked(Int32)
Removes the associated sparse/dense index pair from active use.
Declaration
public void RemoveUnchecked(int sparseIndexToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index to remove. |
RemoveUnchecked(Int32, out Int32, out Int32)
Removes the associated sparse/dense index pair from active use. Out parameters used to manage parallel data arrays.
Declaration
public void RemoveUnchecked(int sparseIndexToRemove, out int indexToSwapFrom, out int indexToSwapTo)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index to remove. |
System.Int32 | indexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at indexToSwapTo. |
System.Int32 | indexToSwapTo | Replace the data array value at this index with the data array value at indexToSwapFrom. |
RemoveUnchecked(Int32, NativeArray<UInt64>)
Removes the associated sparse/dense index pair from active use and increments the version.
Declaration
public void RemoveUnchecked(int sparseIndexToRemove, NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index to remove. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
RemoveUnchecked(Int32, NativeArray<UInt64>, out Int32, out Int32)
Removes the associated sparse/dense index pair from active use and increments the version. Out parameters used to manage parallel data arrays.
Declaration
public void RemoveUnchecked(int sparseIndexToRemove, NativeArray<ulong> versionArray, out int indexToSwapFrom, out int indexToSwapTo)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index to remove. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
System.Int32 | indexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at indexToSwapTo. |
System.Int32 | indexToSwapTo | Replace the data array value at this index with the data array value at indexToSwapFrom. |
RemoveUncheckedFromDenseIndex(Int32)
Removes the associated sparse/dense index pair from active use.
Declaration
public void RemoveUncheckedFromDenseIndex(int denseIndexToRemove)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | denseIndexToRemove | The dense index associated with the sparse index to remove. |
RemoveUncheckedFromDenseIndex(Int32, out Int32)
Removes the associated sparse/dense index pair from active use. Out parameter used to manage parallel data arrays.
Declaration
public void RemoveUncheckedFromDenseIndex(int denseIndexToRemove, out int indexToSwapFrom)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | denseIndexToRemove | The sparse index to remove. |
System.Int32 | indexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at denseIndexToRemove. |
RemoveUncheckedFromDenseIndex(Int32, NativeArray<UInt64>)
Removes the associated sparse/dense index pair from active use.
Declaration
public void RemoveUncheckedFromDenseIndex(int denseIndexToRemove, NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | denseIndexToRemove | The dense index associated with the sparse index to remove. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
RemoveUncheckedFromDenseIndex(Int32, NativeArray<UInt64>, out Int32)
Removes the associated sparse/dense index pair from active use. Out parameter used to manage parallel data arrays.
Declaration
public void RemoveUncheckedFromDenseIndex(int denseIndexToRemove, NativeArray<ulong> versionArray, out int indexToSwapFrom)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | denseIndexToRemove | The sparse index to remove. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |
System.Int32 | indexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at denseIndexToRemove. |
RemoveWithBoundsAndVersionChecks(ref Int32, UInt64, NativeArray<UInt64>, out Int32, out Int32)
Removes the associated sparse/dense index pair from active use. calls.
Declaration
public bool RemoveWithBoundsAndVersionChecks(ref int sparseIndexToRemove, ulong version, NativeArray<ulong> versionArray, out int indexToSwapFrom, out int indexToSwapTo)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index to remove. |
System.UInt64 | version | The version number of the int used to access the sparse index. Used to guard against accessing indices that have been removed and reused. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | The array containing the version number to check against. |
System.Int32 | indexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at indexToSwapTo. |
System.Int32 | indexToSwapTo | Replace the data array value at this index with the data array value at indexToSwapFrom. |
Returns
Type | Description |
---|---|
System.Boolean | True if the element was successfully removed. |
RemoveWithBoundsCheck(ref Int32, out Int32, out Int32)
Removes the entry corresponding to the sparse index if the entry is within bounds and currently in use.
Declaration
public bool RemoveWithBoundsCheck(ref int sparseIndexToRemove, out int dataIndexToSwapFrom, out int dataIndexToSwapTo)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index corresponding to the entry to remove. Cleared to -1 in this operation. |
System.Int32 | dataIndexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at indexToSwapTo. |
System.Int32 | dataIndexToSwapTo | Replace the data array value at this index with the data array value at indexToSwapFrom. |
Returns
Type | Description |
---|---|
System.Boolean | True if the index reference was valid, and thus removed. |
RemoveWithVersionCheck(Int32, UInt64, NativeArray<UInt64>, out Int32, out Int32)
Attempts to remove the associated sparse/dense index pair from active use and increments the version if successful. Out parameters used to manage parallel data arrays.
Declaration
public bool RemoveWithVersionCheck(int sparseIndexToRemove, ulong version, NativeArray<ulong> versionArray, out int indexToSwapFrom, out int indexToSwapTo)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | sparseIndexToRemove | The sparse index to remove. |
System.UInt64 | version | The version number of the int used to access the sparse index. Used to guard against accessing indices that have been removed and reused. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | The array containing the version number to check against. |
System.Int32 | indexToSwapFrom | Set the data array value at this index to default after swapping with the data array value at indexToSwapTo. |
System.Int32 | indexToSwapTo | Replace the data array value at this index with the data array value at indexToSwapFrom. |
Returns
Type | Description |
---|---|
System.Boolean | True if the entry was valid and thus removed. |
Reserve(Int32, Allocator)
Reallocate the dense and sparse arrays with additional capacity if there are not at least
numberToReserve
unused entries.
Declaration
public void Reserve(int numberToReserve, Allocator allocator)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | numberToReserve | The number of unused entries to ensure capacity for. |
Unity.Collections.Allocator | allocator | The allocator to use on expansion. |
Reserve(Int32, Allocator, ref NativeArray<UInt64>)
Reallocate the dense and sparse arrays with additional capacity if there are not at least
numberToReserve
unused entries.
Declaration
public void Reserve(int numberToReserve, Allocator allocator, ref NativeArray<ulong> versionArray)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | numberToReserve | The number of unused entries to ensure capacity for. |
Unity.Collections.Allocator | allocator | The allocator to use on expansion. |
Unity.Collections.NativeArray<System.UInt64> | versionArray | Enables detection of use-after-free errors when using sparse indices as references. |