mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-23 00:38:47 +00:00
Rename UnpackBits to Unpack, PacknBit to Pack(CLR type)
This commit is contained in:
parent
4f3dd908c6
commit
ba6c400a79
@ -10,47 +10,47 @@ public class BoolListTests
|
|||||||
public void Pack8Bit_Should_Pack_Correctly()
|
public void Pack8Bit_Should_Pack_Correctly()
|
||||||
{
|
{
|
||||||
var array = new[] {true, false, true, false, true, false, true, false};
|
var array = new[] {true, false, true, false, true, false, true, false};
|
||||||
Assert.AreEqual(85, array.Pack8Bit()); // 01010101
|
Assert.AreEqual(85, array.PackByte()); // 01010101
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Pack16Bit_Should_Pack_Correctly()
|
public void Pack16Bit_Should_Pack_Correctly()
|
||||||
{
|
{
|
||||||
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
||||||
Assert.AreEqual(2901, array.Pack16Bit()); // 101101010101
|
Assert.AreEqual(2901, array.PackInt16()); // 101101010101
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Pack32Bit_Should_Pack_Correctly()
|
public void Pack32Bit_Should_Pack_Correctly()
|
||||||
{
|
{
|
||||||
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
||||||
Assert.AreEqual(2901, array.Pack32Bit()); // 101101010101
|
Assert.AreEqual(2901, array.PackInt32()); // 101101010101
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Pack64Bit_Should_Pack_Correctly()
|
public void Pack64Bit_Should_Pack_Correctly()
|
||||||
{
|
{
|
||||||
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
var array = new[] {true, false, true, false, true, false, true, false, true, true, false, true};
|
||||||
Assert.AreEqual(2901, array.Pack64Bit()); // 101101010101
|
Assert.AreEqual(2901, array.PackInt64()); // 101101010101
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Pack_ShouldThrow_GivenLargeArray()
|
public void Pack_ShouldThrow_GivenLargeArray()
|
||||||
{
|
{
|
||||||
bool[] array = Enumerable.Repeat(false, 65).ToArray();
|
bool[] array = Enumerable.Repeat(false, 65).ToArray();
|
||||||
Assert.ThrowsException<ArgumentException>(() => array.Pack8Bit());
|
Assert.ThrowsException<ArgumentException>(() => array.PackByte());
|
||||||
Assert.ThrowsException<ArgumentException>(() => array.Pack16Bit());
|
Assert.ThrowsException<ArgumentException>(() => array.PackInt16());
|
||||||
Assert.ThrowsException<ArgumentException>(() => array.Pack32Bit());
|
Assert.ThrowsException<ArgumentException>(() => array.PackInt32());
|
||||||
Assert.ThrowsException<ArgumentException>(() => array.Pack64Bit());
|
Assert.ThrowsException<ArgumentException>(() => array.PackInt64());
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void Pack_ShouldThrow_GivenNull()
|
public void Pack_ShouldThrow_GivenNull()
|
||||||
{
|
{
|
||||||
bool[]? array = null;
|
bool[]? array = null;
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => array!.Pack8Bit());
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackByte());
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => array!.Pack16Bit());
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt16());
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => array!.Pack32Bit());
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt32());
|
||||||
Assert.ThrowsException<ArgumentNullException>(() => array!.Pack64Bit());
|
Assert.ThrowsException<ArgumentNullException>(() => array!.PackInt64());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class ByteTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
||||||
{
|
{
|
||||||
bool[] bits = ((byte)0b11010100).UnpackBits();
|
bool[] bits = ((byte)0b11010100).Unpack();
|
||||||
|
|
||||||
Assert.AreEqual(8, bits.Length);
|
Assert.AreEqual(8, bits.Length);
|
||||||
|
|
||||||
@ -27,7 +27,7 @@ public class ByteTests
|
|||||||
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[8];
|
Span<bool> bits = stackalloc bool[8];
|
||||||
((byte)0b11010100).UnpackBits(bits);
|
((byte)0b11010100).Unpack(bits);
|
||||||
|
|
||||||
Assert.IsFalse(bits[0]);
|
Assert.IsFalse(bits[0]);
|
||||||
Assert.IsFalse(bits[1]);
|
Assert.IsFalse(bits[1]);
|
||||||
@ -42,7 +42,7 @@ public class ByteTests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldRepackEqually()
|
public void UnpackBits_ShouldRepackEqually()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(0b11010100, ((byte)0b11010100).UnpackBits().Pack8Bit());
|
Assert.AreEqual(0b11010100, ((byte)0b11010100).Unpack().PackByte());
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@ -51,7 +51,7 @@ public class ByteTests
|
|||||||
Assert.ThrowsException<ArgumentException>(() =>
|
Assert.ThrowsException<ArgumentException>(() =>
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[0];
|
Span<bool> bits = stackalloc bool[0];
|
||||||
((byte)0b11010100).UnpackBits(bits);
|
((byte)0b11010100).Unpack(bits);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class Int16Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
||||||
{
|
{
|
||||||
bool[] bits = ((short)0b11010100).UnpackBits();
|
bool[] bits = ((short)0b11010100).Unpack();
|
||||||
|
|
||||||
Assert.AreEqual(16, bits.Length);
|
Assert.AreEqual(16, bits.Length);
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public class Int16Tests
|
|||||||
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[16];
|
Span<bool> bits = stackalloc bool[16];
|
||||||
((short)0b11010100).UnpackBits(bits);
|
((short)0b11010100).Unpack(bits);
|
||||||
|
|
||||||
Assert.IsFalse(bits[0]);
|
Assert.IsFalse(bits[0]);
|
||||||
Assert.IsFalse(bits[1]);
|
Assert.IsFalse(bits[1]);
|
||||||
@ -52,7 +52,7 @@ public class Int16Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldRepackEqually()
|
public void UnpackBits_ShouldRepackEqually()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(0b11010100, ((short)0b11010100).UnpackBits().Pack16Bit());
|
Assert.AreEqual(0b11010100, ((short)0b11010100).Unpack().PackInt16());
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@ -61,7 +61,7 @@ public class Int16Tests
|
|||||||
Assert.ThrowsException<ArgumentException>(() =>
|
Assert.ThrowsException<ArgumentException>(() =>
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[0];
|
Span<bool> bits = stackalloc bool[0];
|
||||||
((short)0b11010100).UnpackBits(bits);
|
((short)0b11010100).Unpack(bits);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -9,7 +9,7 @@ public class Int32Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
||||||
{
|
{
|
||||||
bool[] bits = 0b11010100.UnpackBits();
|
bool[] bits = 0b11010100.Unpack();
|
||||||
|
|
||||||
Assert.AreEqual(32, bits.Length);
|
Assert.AreEqual(32, bits.Length);
|
||||||
|
|
||||||
@ -32,7 +32,7 @@ public class Int32Tests
|
|||||||
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[32];
|
Span<bool> bits = stackalloc bool[32];
|
||||||
0b11010100.UnpackBits(bits);
|
0b11010100.Unpack(bits);
|
||||||
|
|
||||||
Assert.IsFalse(bits[0]);
|
Assert.IsFalse(bits[0]);
|
||||||
Assert.IsFalse(bits[1]);
|
Assert.IsFalse(bits[1]);
|
||||||
@ -52,7 +52,7 @@ public class Int32Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldRepackEqually()
|
public void UnpackBits_ShouldRepackEqually()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(0b11010100, 0b11010100.UnpackBits().Pack32Bit());
|
Assert.AreEqual(0b11010100, 0b11010100.Unpack().PackInt32());
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@ -61,7 +61,7 @@ public class Int32Tests
|
|||||||
Assert.ThrowsException<ArgumentException>(() =>
|
Assert.ThrowsException<ArgumentException>(() =>
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[0];
|
Span<bool> bits = stackalloc bool[0];
|
||||||
0b11010100.UnpackBits(bits);
|
0b11010100.Unpack(bits);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
using X10D.Collections;
|
using X10D.Collections;
|
||||||
using X10D.Linq;
|
|
||||||
|
|
||||||
namespace X10D.Tests.Collections;
|
namespace X10D.Tests.Collections;
|
||||||
|
|
||||||
@ -11,7 +10,7 @@ public class Int64Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
public void UnpackBits_ShouldUnpackToArrayCorrectly()
|
||||||
{
|
{
|
||||||
bool[] bits = 0b11010100L.UnpackBits();
|
bool[] bits = 0b11010100L.Unpack();
|
||||||
|
|
||||||
Assert.AreEqual(64, bits.Length);
|
Assert.AreEqual(64, bits.Length);
|
||||||
|
|
||||||
@ -37,7 +36,7 @@ public class Int64Tests
|
|||||||
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
public void UnpackBits_ShouldUnpackToSpanCorrectly()
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[64];
|
Span<bool> bits = stackalloc bool[64];
|
||||||
0b11010100L.UnpackBits(bits);
|
0b11010100L.Unpack(bits);
|
||||||
|
|
||||||
Assert.IsFalse(bits[0]);
|
Assert.IsFalse(bits[0]);
|
||||||
Assert.IsFalse(bits[1]);
|
Assert.IsFalse(bits[1]);
|
||||||
@ -57,7 +56,7 @@ public class Int64Tests
|
|||||||
[TestMethod]
|
[TestMethod]
|
||||||
public void UnpackBits_ShouldRepackEqually()
|
public void UnpackBits_ShouldRepackEqually()
|
||||||
{
|
{
|
||||||
Assert.AreEqual(0b11010100L, 0b11010100L.UnpackBits().Pack64Bit());
|
Assert.AreEqual(0b11010100L, 0b11010100L.Unpack().PackInt64());
|
||||||
}
|
}
|
||||||
|
|
||||||
[TestMethod]
|
[TestMethod]
|
||||||
@ -66,7 +65,7 @@ public class Int64Tests
|
|||||||
Assert.ThrowsException<ArgumentException>(() =>
|
Assert.ThrowsException<ArgumentException>(() =>
|
||||||
{
|
{
|
||||||
Span<bool> bits = stackalloc bool[0];
|
Span<bool> bits = stackalloc bool[0];
|
||||||
0b11010100L.UnpackBits(bits);
|
0b11010100L.Unpack(bits);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
namespace X10D.Collections;
|
namespace X10D.Collections;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Collection-related extension methods for <see cref="IReadOnlyList{T}" /> of <see cref="bool" />.
|
/// Collection-related extension methods for <see cref="IReadOnlyList{T}" /> of <see cref="bool" />.
|
||||||
@ -13,7 +13,7 @@ public static class BoolListExtensions
|
|||||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||||
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 8 elements.</exception>
|
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 8 elements.</exception>
|
||||||
/// <author>Alpha Anar</author>
|
/// <author>Alpha Anar</author>
|
||||||
public static byte Pack8Bit(this IReadOnlyList<bool> source)
|
public static byte PackByte(this IReadOnlyList<bool> source)
|
||||||
{
|
{
|
||||||
if (source is null)
|
if (source is null)
|
||||||
{
|
{
|
||||||
@ -42,7 +42,7 @@ public static class BoolListExtensions
|
|||||||
/// <returns>A 16-bit signed integer containing the packed booleans.</returns>
|
/// <returns>A 16-bit signed integer containing the packed booleans.</returns>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||||
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 16 elements.</exception>
|
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 16 elements.</exception>
|
||||||
public static short Pack16Bit(this IReadOnlyList<bool> source)
|
public static short PackInt16(this IReadOnlyList<bool> source)
|
||||||
{
|
{
|
||||||
if (source is null)
|
if (source is null)
|
||||||
{
|
{
|
||||||
@ -71,7 +71,7 @@ public static class BoolListExtensions
|
|||||||
/// <returns>A 32-bit signed integer containing the packed booleans.</returns>
|
/// <returns>A 32-bit signed integer containing the packed booleans.</returns>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||||
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 32 elements.</exception>
|
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 32 elements.</exception>
|
||||||
public static int Pack32Bit(this IReadOnlyList<bool> source)
|
public static int PackInt32(this IReadOnlyList<bool> source)
|
||||||
{
|
{
|
||||||
if (source is null)
|
if (source is null)
|
||||||
{
|
{
|
||||||
@ -100,7 +100,7 @@ public static class BoolListExtensions
|
|||||||
/// <returns>A 64-bit signed integer containing the packed booleans.</returns>
|
/// <returns>A 64-bit signed integer containing the packed booleans.</returns>
|
||||||
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
/// <exception cref="ArgumentNullException"><paramref name="source" /> is <see langword="null" />.</exception>
|
||||||
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 64 elements.</exception>
|
/// <exception cref="ArgumentException"><paramref name="source" /> contains more than 64 elements.</exception>
|
||||||
public static long Pack64Bit(this IReadOnlyList<bool> source)
|
public static long PackInt64(this IReadOnlyList<bool> source)
|
||||||
{
|
{
|
||||||
if (source is null)
|
if (source is null)
|
||||||
{
|
{
|
||||||
|
@ -12,10 +12,10 @@ public static class ByteExtensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <returns>An array of <see cref="bool" /> with length 8.</returns>
|
/// <returns>An array of <see cref="bool" /> with length 8.</returns>
|
||||||
public static bool[] UnpackBits(this byte value)
|
public static bool[] Unpack(this byte value)
|
||||||
{
|
{
|
||||||
Span<bool> buffer = stackalloc bool[Size];
|
Span<bool> buffer = stackalloc bool[Size];
|
||||||
value.UnpackBits(buffer);
|
value.Unpack(buffer);
|
||||||
return buffer.ToArray();
|
return buffer.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -26,7 +26,7 @@ public static class ByteExtensions
|
|||||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||||
/// <author>Alpha Anar</author>
|
/// <author>Alpha Anar</author>
|
||||||
public static void UnpackBits(this byte value, Span<bool> destination)
|
public static void Unpack(this byte value, Span<bool> destination)
|
||||||
{
|
{
|
||||||
if (destination.Length < Size)
|
if (destination.Length < Size)
|
||||||
{
|
{
|
||||||
|
@ -12,10 +12,10 @@ public static class Int16Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <returns>An array of <see cref="bool" /> with length 16.</returns>
|
/// <returns>An array of <see cref="bool" /> with length 16.</returns>
|
||||||
public static bool[] UnpackBits(this short value)
|
public static bool[] Unpack(this short value)
|
||||||
{
|
{
|
||||||
Span<bool> buffer = stackalloc bool[Size];
|
Span<bool> buffer = stackalloc bool[Size];
|
||||||
value.UnpackBits(buffer);
|
value.Unpack(buffer);
|
||||||
return buffer.ToArray();
|
return buffer.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,13 +25,13 @@ public static class Int16Extensions
|
|||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||||
public static void UnpackBits(this short value, Span<bool> destination)
|
public static void Unpack(this short value, Span<bool> destination)
|
||||||
{
|
{
|
||||||
if (destination.Length < Size)
|
if (destination.Length < Size)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Destination must be at least {Size} in length.", nameof(destination));
|
throw new ArgumentException($"Destination must be at least {Size} in length.", nameof(destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var index = 0; index < Size; index++)
|
for (var index = 0; index < Size; index++)
|
||||||
{
|
{
|
||||||
destination[index] = (value & (1 << index)) != 0;
|
destination[index] = (value & (1 << index)) != 0;
|
||||||
|
@ -12,10 +12,10 @@ public static class Int32Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <returns>An array of <see cref="bool" /> with length 32.</returns>
|
/// <returns>An array of <see cref="bool" /> with length 32.</returns>
|
||||||
public static bool[] UnpackBits(this int value)
|
public static bool[] Unpack(this int value)
|
||||||
{
|
{
|
||||||
Span<bool> buffer = stackalloc bool[Size];
|
Span<bool> buffer = stackalloc bool[Size];
|
||||||
value.UnpackBits(buffer);
|
value.Unpack(buffer);
|
||||||
return buffer.ToArray();
|
return buffer.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,13 +25,13 @@ public static class Int32Extensions
|
|||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||||
public static void UnpackBits(this int value, Span<bool> destination)
|
public static void Unpack(this int value, Span<bool> destination)
|
||||||
{
|
{
|
||||||
if (destination.Length < Size)
|
if (destination.Length < Size)
|
||||||
{
|
{
|
||||||
throw new ArgumentException($"Destination must be at least {Size} in length.", nameof(destination));
|
throw new ArgumentException($"Destination must be at least {Size} in length.", nameof(destination));
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var index = 0; index < Size; index++)
|
for (var index = 0; index < Size; index++)
|
||||||
{
|
{
|
||||||
destination[index] = (value & (1 << index)) != 0;
|
destination[index] = (value & (1 << index)) != 0;
|
||||||
|
@ -12,10 +12,10 @@ public static class Int64Extensions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <returns>An array of <see cref="bool" /> with length 64.</returns>
|
/// <returns>An array of <see cref="bool" /> with length 64.</returns>
|
||||||
public static bool[] UnpackBits(this long value)
|
public static bool[] Unpack(this long value)
|
||||||
{
|
{
|
||||||
Span<bool> buffer = stackalloc bool[Size];
|
Span<bool> buffer = stackalloc bool[Size];
|
||||||
value.UnpackBits(buffer);
|
value.Unpack(buffer);
|
||||||
return buffer.ToArray();
|
return buffer.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -25,7 +25,7 @@ public static class Int64Extensions
|
|||||||
/// <param name="value">The value to unpack.</param>
|
/// <param name="value">The value to unpack.</param>
|
||||||
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
/// <param name="destination">When this method returns, contains the unpacked booleans from <paramref name="value" />.</param>
|
||||||
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
/// <exception cref="ArgumentException"><paramref name="destination" /> is not large enough to contain the result.</exception>
|
||||||
public static void UnpackBits(this long value, Span<bool> destination)
|
public static void Unpack(this long value, Span<bool> destination)
|
||||||
{
|
{
|
||||||
if (destination.Length < Size)
|
if (destination.Length < Size)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user