Struct NativeBitArray
Arbitrary sized array of bits.
Namespace: Unity.Collections
Syntax
[NativeContainer]
public struct NativeBitArray : INativeDisposable, IDisposable
Constructors
NativeBitArray(Int32, Allocator, NativeArrayOptions)
Constructs a new container with the specified initial capacity and type of memory allocation.
Declaration
public NativeBitArray(int numBits, Allocator allocator, NativeArrayOptions options = NativeArrayOptions.ClearMemory)
Parameters
Type | Name | Description |
---|---|---|
Int32 | numBits | Number of bits. |
Allocator | allocator | A member of the Unity.Collections.Allocator enumeration. |
NativeArrayOptions | options | Memory should be cleared on allocation or left uninitialized. |
Properties
IsCreated
Reports whether memory for the container is allocated.
Declaration
public bool IsCreated { get; }
Property Value
Type | Description |
---|---|
Boolean | True if this container object's internal storage has been allocated. |
Remarks
Note that the container storage is not created if you use the default constructor. You must specify at least an allocation type to construct a usable container.
Length
Number of bits.
Declaration
public int Length { get; }
Property Value
Type | Description |
---|---|
Int32 | The number of bits. |
Methods
AsNativeArray<T>()
Return a native array that aliases the original bit array contents.
Declaration
public NativeArray<T> AsNativeArray<T>()
where T : struct
Returns
Type | Description |
---|---|
NativeArray<T> | Native array view into bit array. |
Type Parameters
Name | Description |
---|---|
T | The type of the elements in the container. |
Exceptions
Type | Condition |
---|---|
InvalidOperationException | Thrown if output size doesn't match input, or if reinterpreted data would be truncated. |
Clear()
Clear all bits to 0.
Declaration
public void Clear()
Copy(Int32, Int32, Int32)
Copy block of bits from source to destination.
Declaration
public void Copy(int dstPos, int srcPos, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dstPos | Destination position in bit array. |
Int32 | srcPos | Source position in bit array. |
Int32 | numBits | Number of bits to copy. |
Copy(Int32, ref NativeBitArray, Int32, Int32)
Copy block of bits from source to destination.
Declaration
public void Copy(int dstPos, ref NativeBitArray srcBitArray, int srcPos, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | dstPos | Destination position in bit array. |
NativeBitArray | srcBitArray | Source bit array from which bits will be copied. |
Int32 | srcPos | Source position in bit array. |
Int32 | numBits | Number of bits to copy. |
CountBits(Int32, Int32)
Calculate number of set bits.
Declaration
public int CountBits(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Int32 | numBits | Number of bits to perform count. |
Returns
Type | Description |
---|---|
Int32 | Number of set bits. |
Dispose()
Disposes of this container and deallocates its memory immediately.
Declaration
public void Dispose()
Dispose(JobHandle)
Safely disposes of this container and deallocates its memory when the jobs that use it have completed.
Declaration
public JobHandle Dispose(JobHandle inputDeps)
Parameters
Type | Name | Description |
---|---|---|
JobHandle | inputDeps | The job handle or handles for any scheduled jobs that use this container. |
Returns
Type | Description |
---|---|
JobHandle | A new job handle containing the prior handles as well as the handle for the job that deletes the container. |
Implements
Remarks
You can call this function dispose of the container immediately after scheduling the job. Pass
the JobHandle returned by
the Job.Schedule
method using the jobHandle
parameter so the job scheduler can dispose the container after all jobs
using it have run.
Find(Int32, Int32)
Performs a linear search for a consecutive sequence of 0s of a given length in the bit array.
Declaration
public int Find(int pos, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position to start search in bit array. |
Int32 | numBits | Number of 0-bits to find. |
Returns
Type | Description |
---|---|
Int32 | Returns index of first bit of 0-bit range, or int.MaxValue if 0-bit range is not found. |
Find(Int32, Int32, Int32)
Performs a linear search for a consecutive sequence of 0s of a given length in the bit array.
Declaration
public int Find(int pos, int count, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position to start search in bit array. |
Int32 | count | Number of bits to search. |
Int32 | numBits | Number of 0-bits to find. |
Returns
Type | Description |
---|---|
Int32 | Returns index of first bit of 0-bit range, or int.MaxValue if 0-bit range is not found. |
GetBits(Int32, Int32)
Returns all bits in range as ulong.
Declaration
public ulong GetBits(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Int32 | numBits | Number of bits to get (must be 1-64). |
Returns
Type | Description |
---|---|
UInt64 | Returns requested range of bits. |
IsSet(Int32)
Returns true is bit at position is set.
Declaration
public bool IsSet(int pos)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Returns
Type | Description |
---|---|
Boolean | Returns true if bit is set. |
Set(Int32, Boolean)
Set single bit to desired boolean value.
Declaration
public void Set(int pos, bool value)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Boolean | value | Value of bits to set. |
SetBits(Int32, Boolean, Int32)
Set bits to desired boolean value.
Declaration
public void SetBits(int pos, bool value, int numBits)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Boolean | value | Value of bits to set. |
Int32 | numBits | Number of bits to set. |
SetBits(Int32, UInt64, Int32)
Sets bits in range as ulong.
Declaration
public void SetBits(int pos, ulong value, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
UInt64 | value | Value of bits to set. |
Int32 | numBits | Number of bits to set (must be 1-64). |
TestAll(Int32, Int32)
Returns true if all of bits in range are set.
Declaration
public bool TestAll(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Int32 | numBits | Number of bits to test. |
Returns
Type | Description |
---|---|
Boolean | Returns true if all bits are set. |
TestAny(Int32, Int32)
Returns true if any of bits in range are set.
Declaration
public bool TestAny(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Int32 | numBits | Number of bits to test. |
Returns
Type | Description |
---|---|
Boolean | Returns true if at least one bit is set. |
TestNone(Int32, Int32)
Returns true if none of bits in range are set.
Declaration
public bool TestNone(int pos, int numBits = 1)
Parameters
Type | Name | Description |
---|---|---|
Int32 | pos | Position in bit array. |
Int32 | numBits | Number of bits to test. |
Returns
Type | Description |
---|---|
Boolean | Returns true if none of bits are set. |