Skip to content

Commit

Permalink
simplifying BitArray.setBulk
Browse files Browse the repository at this point in the history
  • Loading branch information
micjahn committed Jan 19, 2025
1 parent 9859cfd commit 053916d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 13 deletions.
15 changes: 5 additions & 10 deletions Source/lib/common/BitArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,17 +189,12 @@ public int getNextUnset(int from)
return result > size ? size : result;
}

/// <summary> Sets a block of 32 bits, starting at bit i.
///
/// </summary>
/// <param name="i">first bit to set
/// </param>
/// <param name="newBits">the new value of the next 32 bits. Note again that the least-significant bit
/// corresponds to bit i, the next-least-significant to i+1, and so on.
/// </param>
public void setBulk(int i, int newBits)
/// <summary> Sets a block of 32 bits, starting at bit i.</summary>
/// <param name="blockIndex">index position of the new 32 bit block</param>
/// <param name="newBits">the new value of the next 32 bits.</param>
public void setBulk(int blockIndex, int newBits)
{
bits[i >> 5] = newBits;
bits[blockIndex] = newBits;
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Source/lib/common/BitMatrix.cs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ public BitArray getRow(int y, BitArray row)
int offset = y * rowSize;
for (int x = 0; x < rowSize; x++)
{
row.setBulk(x << 5, bits[offset + x]);
row.setBulk(x, bits[offset + x]);
}
return row;
}
Expand Down
3 changes: 1 addition & 2 deletions Source/test/src/common/BitArrayTestCase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,11 @@ public void testGetNextSet5()
}
}


[Test]
public void testSetBulk()
{
BitArray array = new BitArray(64);
array.setBulk(32, -65536);
array.setBulk(1, -65536);
for (int i = 0; i < 48; i++)
{
Assert.IsFalse(array[i]);
Expand Down

0 comments on commit 053916d

Please sign in to comment.