Struct FreeList
An array where indices are allocated from and stored in an in-place linked list. Allocating or deallocating a single int from this array is very fast, as is single datum lookup, but neither the allocated indices nor the free indices can be reliably iterated without an external data structure. This structure can be adapted to an arbitrary of external, parallel arrays.
Namespace: GDX.Collections
Syntax
public struct FreeList
Constructors
| Improve this Doc View SourceFreeList(Int32)
Declaration
public FreeList(int initialCapacity)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | initialCapacity | The initial capacity of the array. |
Fields
| Improve this Doc View SourceCount
The total number of currently-allocated indices.
Declaration
public int Count
Field Value
Type | Description |
---|---|
System.Int32 |
CurrentFreeIndex
The next available index of the free-list.
Declaration
public int CurrentFreeIndex
Field Value
Type | Description |
---|---|
System.Int32 |
Indices
Data storage for allocated indices as well as the in-place free-list.
Declaration
public int[] Indices
Field Value
Type | Description |
---|---|
System.Int32[] |
Methods
| Improve this Doc View SourceAddUnchecked(Int32)
Allocates an index from the free-list and stores an integer there, without checking for expansion.
Declaration
public int AddUnchecked(int data)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | data | The integer value to store at the allocated index. |
Returns
Type | Description |
---|---|
System.Int32 | The index allocated from the free-list. |
AddWithExpandCheck(Int32, out Int32)
Allocates an index from the free-list and stores an integer there, expanding the array by twice the current size if necessary.
Declaration
public bool AddWithExpandCheck(int data, out int allocatedIndex)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | data | The integer value to store at the allocated index. |
System.Int32 | allocatedIndex | The index allocated from the free-list. |
Returns
Type | Description |
---|---|
System.Boolean | True if the array expanded. |
AddWithExpandCheck(Int32, out Int32, Int32)
Allocates an index from the free-list and stores an integer there, expanding the array if necessary.
Declaration
public bool AddWithExpandCheck(int data, out int allocatedIndex, int expandBy)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | data | The integer value to store at the allocated index. |
System.Int32 | allocatedIndex | The index allocated from the free-list. |
System.Int32 | expandBy | How much the array should expand by when out of space. |
Returns
Type | Description |
---|---|
System.Boolean | True if the array expanded. |
Clear()
Removes all allocated data and rebuilds the free-list.
Declaration
public void Clear()
GetAndRemoveAt(Int32)
Retrieves the value stored at the given index and deallocates the index, adding it to the free-list.
Declaration
public int GetAndRemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index to add to the free-list. |
Returns
Type | Description |
---|---|
System.Int32 | The value stored at the given index. |
RemoveAt(Int32)
Deallocates the given index and adds it to the free-list.
Declaration
public void RemoveAt(int index)
Parameters
Type | Name | Description |
---|---|---|
System.Int32 | index | The index to add to the free-list. |