Struct UnsafeBitSet
- Namespace
- Misaki.HighPerformance.LowLevel.Collections
- Assembly
- Misaki.HighPerformance.LowLevel.dll
public struct UnsafeBitSet : IDisposable, IEquatable<UnsafeBitSet>
- Implements
- Inherited Members
Constructors
UnsafeBitSet()
Initializes a new instance of UnsafeBitSet with a default size of 1 and a persistent allocation handle.
public UnsafeBitSet()
UnsafeBitSet(int, AllocationHandle, AllocationOption)
Initializes a new instance of the UnsafeBitSet class.
public UnsafeBitSet(int minimalLength, AllocationHandle handle, AllocationOption option = AllocationOption.None)
Parameters
minimalLengthintThe minimal length in bits.
handleAllocationHandleThe allocation handle.
optionAllocationOptionThe allocation option.
UnsafeBitSet(Span<uint>, AllocationHandle)
Initializes a new instance of the UnsafeBitSet class.
public UnsafeBitSet(Span<uint> bits, AllocationHandle handle)
Parameters
bitsSpan<uint>The bits to initialize the bitset with. The length of the bitset will be determined by the length of this span.
handleAllocationHandleThe allocation handle.
Properties
Count
Gets the total number of bits represented by the current instance.
public readonly int Count { get; }
Property Value
HighestBit
The highest bit set.
public readonly int HighestBit { get; }
Property Value
HighestIndex
The highest uint index in use inside the Misaki.HighPerformance.LowLevel.Collections.UnsafeBitSet._bits-array.
public readonly int HighestIndex { get; }
Property Value
IsCreated
public readonly bool IsCreated { get; }
Property Value
Methods
ANDC(UnsafeBitSet)
Performs a bitwise AND NOT operation between the current bit set and the specified bit set, updating the current bit set in place.
public void ANDC(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe bit set whose bits will be inverted and ANDed with the current bit set. Must have the same length as the current bit set.
Exceptions
- ArgumentException
Thrown when the specified bit set does not have the same length as the current bit set.
All(UnsafeBitSet)
Checks if all bits from this instance match those of the other instance.
public readonly bool All(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe other UnsafeBitSet.
Returns
- bool
True if they match, false if not.
And(UnsafeBitSet)
Performs a bitwise AND operation between the current bit set and the specified bit set, updating the current bit set in place.
public void And(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe bit set to combine with the current bit set using a bitwise AND operation. Must have the same length as the current bit set.
Exceptions
- ArgumentException
Thrown when
otherdoes not have the same length as the current bit set.
Any(UnsafeBitSet)
Checks if any bits from this instance match those of the other instance.
public readonly bool Any(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe other UnsafeBitSet.
Returns
- bool
True if they match, false if not.
AsSpan()
Creates a Span<T> to access the Misaki.HighPerformance.LowLevel.Collections.UnsafeBitSet._bits.
public readonly Span<uint> AsSpan()
Returns
AsSpan(Span<uint>, bool)
Copies the bits into a Span<T>.
public readonly Span<uint> AsSpan(Span<uint> span, bool zero = true)
Parameters
spanSpan<uint>The Span<T> to copy into.
zeroboolIf true, it will zero the unused space from the
span.
Returns
ClearAll()
Clears all set bits.
public void ClearAll()
ClearBit(int)
Clears the bit at the given index.
public void ClearBit(int index)
Parameters
indexintThe index.
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
Equals(UnsafeBitSet)
Indicates whether the current object is equal to another object of the same type.
public readonly bool Equals(UnsafeBitSet other)
Parameters
otherUnsafeBitSetAn object to compare with this object.
Returns
Equals(object?)
Indicates whether this instance and a specified object are equal.
public override readonly bool Equals(object? obj)
Parameters
objobjectThe object to compare with the current instance.
Returns
- bool
true if
objand this instance are the same type and represent the same value; otherwise, false.
Exclusive(UnsafeBitSet)
Checks if exactly all bits from this instance match those of the other instance.
public readonly bool Exclusive(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe other UnsafeBitSet.
Returns
- bool
True if they match, false if not.
GetHashCode()
Returns the hash code for this instance.
public override readonly int GetHashCode()
Returns
- int
A 32-bit signed integer that is the hash code for this instance.
GetIterator(int)
[UnscopedRef]
public UnsafeBitSet.Iterator GetIterator(int start = 0)
Parameters
startint
Returns
IsSet(int)
Checks whether a bit is set at the index.
public readonly bool IsSet(int index)
Parameters
indexintThe index.
Returns
- bool
True if it is, otherwise false
Nand(UnsafeBitSet)
Performs a bitwise NAND operation between the current bit set and the specified bit set, updating the current bit set in place.
public void Nand(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe bit set to combine with the current bit set using the NAND operation. Must have the same length as the current bit set.
Exceptions
- ArgumentException
Thrown if
otherdoes not have the same length as the current bit set.
NextSetBit(int)
Finds the next set bit at or after startIndex, or -1 if none.
public readonly int NextSetBit(int startIndex)
Parameters
startIndexint
Returns
None(UnsafeBitSet)
Checks if none bits from this instance match those of the other instance.
public readonly bool None(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe other UnsafeBitSet.
Returns
- bool
True if none match, false if not.
Not()
Inverts all bits in the current vector, replacing each bit with its logical complement.
public void Not()
Or(UnsafeBitSet)
Performs a bitwise OR operation between the current bit set and the specified bit set, updating the current set in place.
public void Or(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe bit set to combine with the current set using a bitwise OR operation. Must have the same length as the current bit set.
Exceptions
- ArgumentException
Thrown if
otherdoes not have the same length as the current bit set.
RequiredLength(int)
Determines the required length of an UnsafeBitSet to hold the passed ID or bit.
public static int RequiredLength(int id)
Parameters
idintThe ID or bit.
Returns
Resize(int, AllocationOption)
public void Resize(int minimalLength, AllocationOption option = AllocationOption.None)
Parameters
minimalLengthintoptionAllocationOption
SetAll()
Sets all bits.
public void SetAll()
SetBit(int)
Sets a bit at the given index. Resizes its internal array if necessary.
public void SetBit(int index)
Parameters
indexintThe index.
ToString()
Returns the fully qualified type name of this instance.
public override readonly string ToString()
Returns
- string
The fully qualified type name.
Xor(UnsafeBitSet)
Performs a bitwise exclusive OR (XOR) operation between the current bit set and the specified bit set.
public void Xor(UnsafeBitSet other)
Parameters
otherUnsafeBitSetThe bit set to XOR with the current instance. Must have the same length as the current bit set.
Exceptions
- ArgumentException
Thrown if
otherdoes not have the same length as the current bit set.
Operators
operator ==(UnsafeBitSet, UnsafeBitSet)
public static bool operator ==(UnsafeBitSet left, UnsafeBitSet right)
Parameters
leftUnsafeBitSetrightUnsafeBitSet
Returns
operator !=(UnsafeBitSet, UnsafeBitSet)
public static bool operator !=(UnsafeBitSet left, UnsafeBitSet right)
Parameters
leftUnsafeBitSetrightUnsafeBitSet