Show / Hide Table of Contents

Struct BitVector

A 32-bit vector with simple operations for getting and setting bits.

Implements
System.IEquatable<BitVector>
Inherited Members
System.Object.Equals(System.Object, System.Object)
System.Object.GetType()
System.Object.ReferenceEquals(System.Object, System.Object)
Namespace: SudokuSpice
Assembly: SudokuSpice.dll
Syntax
public struct BitVector : IEquatable<BitVector>

Constructors

| Improve this Doc View Source

BitVector(UInt32)

Constructs a bit vector with the given data.

Declaration
public BitVector(uint data)
Parameters
Type Name Description
System.UInt32 data

The data to use for this bit vector.

Fields

| Improve this Doc View Source

NumBits

The number of bits (i.e. the capacity) contained by a BitVector.

Declaration
public const int NumBits = 32
Field Value
Type Description
System.Int32

Properties

| Improve this Doc View Source

Data

Gets the data stored in this bit vector as an unsigned int.

Declaration
public uint Data { get; }
Property Value
Type Description
System.UInt32
| Improve this Doc View Source

IsEmpty

Checks if this vector is empty (i.e. no bits are set).

Declaration
public bool IsEmpty { get; }
Property Value
Type Description
System.Boolean

True if empty.

Methods

| Improve this Doc View Source

ComputeCount()

Gets the count of bits that are set.

Declaration
public int ComputeCount()
Returns
Type Description
System.Int32
Remarks

This relies on the System.Runtime.Intrinsics.X86.Popcnt hardware intrinsic to be efficient. If this operation is not available on your hardware, then this function falls back to a less efficient software-based approach.

| Improve this Doc View Source

ComputeLastSetBit()

Computes the last bit that is set, or -1 if none are set.

Declaration
public int ComputeLastSetBit()
Returns
Type Description
System.Int32
| Improve this Doc View Source

CreateWithSize(Int32)

Creates a bit vector with only the first size bits set to true.

Declaration
public static BitVector CreateWithSize(int size)
Parameters
Type Name Description
System.Int32 size

The number of bits to set.

Returns
Type Description
BitVector
| Improve this Doc View Source

Equals(BitVector)

Declaration
public bool Equals(BitVector other)
Parameters
Type Name Description
BitVector other
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Equals(Object)

Declaration
public override bool Equals(object obj)
Parameters
Type Name Description
System.Object obj
Returns
Type Description
System.Boolean
Overrides
System.ValueType.Equals(System.Object)
| Improve this Doc View Source

FindDifference(BitVector, BitVector)

Creates a bit vector that is the difference of the given vectors.

Declaration
public static BitVector FindDifference(BitVector a, BitVector b)
Parameters
Type Name Description
BitVector a

One bit vector.

BitVector b

The other bit vector.

Returns
Type Description
BitVector

A new BitVector that is the union of the given vectors.

| Improve this Doc View Source

FindIntersect(BitVector, BitVector)

Creates a bit vector that is the intersect of the given vectors.

Declaration
public static BitVector FindIntersect(BitVector a, BitVector b)
Parameters
Type Name Description
BitVector a

One bit vector.

BitVector b

The other bit vector.

Returns
Type Description
BitVector

A new BitVector that is the intersect of the given vectors.

| Improve this Doc View Source

FindUnion(BitVector, BitVector)

Creates a bit vector that is the union of the given vectors.

Declaration
public static BitVector FindUnion(BitVector a, BitVector b)
Parameters
Type Name Description
BitVector a

One bit vector.

BitVector b

The other bit vector.

Returns
Type Description
BitVector

A new BitVector that is the union of the given vectors.

| Improve this Doc View Source

GetHashCode()

Declaration
public override int GetHashCode()
Returns
Type Description
System.Int32
Overrides
System.ValueType.GetHashCode()
| Improve this Doc View Source

IsBitSet(Int32)

Checks if the bit is true at the given index.

Declaration
public bool IsBitSet(int bit)
Parameters
Type Name Description
System.Int32 bit

The zero-based index of the bit to check.

Returns
Type Description
System.Boolean

True if set.

| Improve this Doc View Source

IsSubsetOf(BitVector)

Determines if this vector is a subset of the given vector (i.e. all bits set in this vector are also set in other).

Declaration
public bool IsSubsetOf(BitVector other)
Parameters
Type Name Description
BitVector other

The possible superset.

Returns
Type Description
System.Boolean

True if this is equal to or a subset of the given vector.

| Improve this Doc View Source

PopulateSetBits(Span<Int32>)

Populates a provided Span with the indices of set bits, and returns the number of set bits it populated.

This method will return if it reaches the end of the provided setIndices span, so if setIndices has size N, then this will only populate the indices for the first N set bits, and will return N. If there are less setBits than N, say M, the values of setIndices from setIndices[M] to setIndices[N-1] are left unchanged.

Declaration
public int PopulateSetBits(Span<int> setIndices)
Parameters
Type Name Description
System.Span<System.Int32> setIndices

A span to fill with the indices of set bits. All values will be written to

Returns
Type Description
System.Int32

The number of set bits that have been populated into setIndices

Remarks

This operation is slightly more efficient on average when System.Runtime.Intrinsics.X86.Popcnt is supported. Worst case performance is roughly the same.

| Improve this Doc View Source

SetBit(Int32)

Sets the given bit index in the given vector. Leaves other bits unchanged.

Declaration
public void SetBit(int bit)
Parameters
Type Name Description
System.Int32 bit

The zero-based index of the bit to set.

| Improve this Doc View Source

ToString()

Returns this bitvector as a binary-formatted string (eg. 1011).

Declaration
public override string ToString()
Returns
Type Description
System.String
Overrides
System.ValueType.ToString()
| Improve this Doc View Source

UnsetBit(Int32)

Unsets the given bit index in the given vector. Leaves other bits unchanged.

Declaration
public void UnsetBit(int bit)
Parameters
Type Name Description
System.Int32 bit

The zero-based index of the bit to unset.

Operators

| Improve this Doc View Source

Equality(BitVector, BitVector)

Declaration
public static bool operator ==(BitVector a, BitVector b)
Parameters
Type Name Description
BitVector a
BitVector b
Returns
Type Description
System.Boolean
| Improve this Doc View Source

Inequality(BitVector, BitVector)

Declaration
public static bool operator !=(BitVector a, BitVector b)
Parameters
Type Name Description
BitVector a
BitVector b
Returns
Type Description
System.Boolean

Implements

System.IEquatable<T>
  • Improve this Doc
  • View Source
In This Article
Back to top Generated by DocFX