From f668c309a28fed67363926f9b7f49bd1f285ccf7 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Wed, 9 Sep 2026 23:24:17 +1000 Subject: [PATCH] Add BitArray HasAllSet, HasAnySet and PopCount * HasAllSet() and HasAnySet(), added in net8 * PopCount(), added in net11 BitArray had no polyfills at all, so this adds the section. HasAllSet returns true for an empty BitArray, matching net11, since the condition is vacuous. Tests cover lengths either side of a 32 bit word boundary, because the unused high bits of the last word must not be counted. --- apiCount.include.md | 44 +++--- api_list.include.md | 7 + assemblySize.include.md | 84 +++++------ readme.md | 139 +++++++++--------- src/Consume/Consume.cs | 8 + src/Polyfill/Polyfill_BitArray.cs | 66 +++++++++ src/Split/net10.0/Polyfill_BitArray.cs | 22 +++ src/Split/net461/Polyfill_BitArray.cs | 50 +++++++ src/Split/net462/Polyfill_BitArray.cs | 50 +++++++ src/Split/net47/Polyfill_BitArray.cs | 50 +++++++ src/Split/net471/Polyfill_BitArray.cs | 50 +++++++ src/Split/net472/Polyfill_BitArray.cs | 50 +++++++ src/Split/net48/Polyfill_BitArray.cs | 50 +++++++ src/Split/net481/Polyfill_BitArray.cs | 50 +++++++ src/Split/net5.0/Polyfill_BitArray.cs | 50 +++++++ src/Split/net6.0/Polyfill_BitArray.cs | 50 +++++++ src/Split/net7.0/Polyfill_BitArray.cs | 50 +++++++ src/Split/net8.0/Polyfill_BitArray.cs | 22 +++ src/Split/net9.0/Polyfill_BitArray.cs | 22 +++ src/Split/netcoreapp2.0/Polyfill_BitArray.cs | 50 +++++++ src/Split/netcoreapp2.1/Polyfill_BitArray.cs | 50 +++++++ src/Split/netcoreapp2.2/Polyfill_BitArray.cs | 50 +++++++ src/Split/netcoreapp3.0/Polyfill_BitArray.cs | 50 +++++++ src/Split/netcoreapp3.1/Polyfill_BitArray.cs | 50 +++++++ src/Split/netstandard2.0/Polyfill_BitArray.cs | 50 +++++++ src/Split/netstandard2.1/Polyfill_BitArray.cs | 50 +++++++ src/Split/uap10.0/Polyfill_BitArray.cs | 50 +++++++ src/Tests/PolyfillTests_BitArray.cs | 79 ++++++++++ 28 files changed, 1263 insertions(+), 130 deletions(-) create mode 100644 src/Polyfill/Polyfill_BitArray.cs create mode 100644 src/Split/net10.0/Polyfill_BitArray.cs create mode 100644 src/Split/net461/Polyfill_BitArray.cs create mode 100644 src/Split/net462/Polyfill_BitArray.cs create mode 100644 src/Split/net47/Polyfill_BitArray.cs create mode 100644 src/Split/net471/Polyfill_BitArray.cs create mode 100644 src/Split/net472/Polyfill_BitArray.cs create mode 100644 src/Split/net48/Polyfill_BitArray.cs create mode 100644 src/Split/net481/Polyfill_BitArray.cs create mode 100644 src/Split/net5.0/Polyfill_BitArray.cs create mode 100644 src/Split/net6.0/Polyfill_BitArray.cs create mode 100644 src/Split/net7.0/Polyfill_BitArray.cs create mode 100644 src/Split/net8.0/Polyfill_BitArray.cs create mode 100644 src/Split/net9.0/Polyfill_BitArray.cs create mode 100644 src/Split/netcoreapp2.0/Polyfill_BitArray.cs create mode 100644 src/Split/netcoreapp2.1/Polyfill_BitArray.cs create mode 100644 src/Split/netcoreapp2.2/Polyfill_BitArray.cs create mode 100644 src/Split/netcoreapp3.0/Polyfill_BitArray.cs create mode 100644 src/Split/netcoreapp3.1/Polyfill_BitArray.cs create mode 100644 src/Split/netstandard2.0/Polyfill_BitArray.cs create mode 100644 src/Split/netstandard2.1/Polyfill_BitArray.cs create mode 100644 src/Split/uap10.0/Polyfill_BitArray.cs create mode 100644 src/Tests/PolyfillTests_BitArray.cs diff --git a/apiCount.include.md b/apiCount.include.md index c6931d36..78c0456c 100644 --- a/apiCount.include.md +++ b/apiCount.include.md @@ -1,28 +1,28 @@ -**API count: 1052** +**API count: 1055** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 986 | -| `net462` | 986 | -| `net47` | 985 | -| `net471` | 984 | -| `net472` | 980 | -| `net48` | 980 | -| `net481` | 980 | -| `netstandard2.0` | 982 | -| `netstandard2.1` | 835 | -| `netcoreapp2.0` | 905 | -| `netcoreapp2.1` | 846 | -| `netcoreapp2.2` | 846 | -| `netcoreapp3.0` | 801 | -| `netcoreapp3.1` | 800 | -| `net5.0` | 672 | -| `net6.0` | 573 | -| `net7.0` | 418 | -| `net8.0` | 299 | -| `net9.0` | 205 | -| `net10.0` | 151 | +| `net461` | 991 | +| `net462` | 991 | +| `net47` | 990 | +| `net471` | 989 | +| `net472` | 985 | +| `net48` | 985 | +| `net481` | 985 | +| `netstandard2.0` | 987 | +| `netstandard2.1` | 840 | +| `netcoreapp2.0` | 910 | +| `netcoreapp2.1` | 851 | +| `netcoreapp2.2` | 851 | +| `netcoreapp3.0` | 806 | +| `netcoreapp3.1` | 805 | +| `net5.0` | 677 | +| `net6.0` | 578 | +| `net7.0` | 423 | +| `net8.0` | 304 | +| `net9.0` | 210 | +| `net10.0` | 156 | | `net11.0` | 58 | -| `uap10.0` | 972 | +| `uap10.0` | 977 | diff --git a/api_list.include.md b/api_list.include.md index a0f45e66..af4bcdee 100644 --- a/api_list.include.md +++ b/api_list.include.md @@ -83,6 +83,13 @@ * `void WriteSingleLittleEndian(Span, float)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.buffers.binary.binaryprimitives.writesinglelittleendian?view=net-11.0) +#### BitArray + + * `bool HasAllSet()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.hasallset?view=net-11.0) + * `bool HasAnySet()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.hasanyset?view=net-11.0) + * `int PopCount()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.popcount?view=net-11.0) + + #### Boolean * `bool TryFormat(Span, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.boolean.tryformat?view=net-11.0) diff --git a/assemblySize.include.md b/assemblySize.include.md index 84d31564..32512eea 100644 --- a/assemblySize.include.md +++ b/assemblySize.include.md @@ -2,51 +2,51 @@ | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 363.5KB | +355.5KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| netstandard2.1 | 8.5KB | 317.5KB | +309.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 362.0KB | +353.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | -| net462 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| net47 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 364.5KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net472 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +7.0KB | +8.0KB | +12.5KB | -| net48 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +5.5KB | +8.0KB | +12.5KB | -| net481 | 8.5KB | 363.5KB | +355.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| netcoreapp2.0 | 9.0KB | 341.0KB | +332.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 315.0KB | +305.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 313.0KB | +303.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net5.0 | 9.5KB | 277.5KB | +268.0KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 218.5KB | +208.5KB | +10.0KB | +7.0KB | +1.0KB | +3.5KB | -| net7.0 | 10.0KB | 180.5KB | +170.5KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | -| net8.0 | 9.5KB | 151.0KB | +141.5KB | +8.5KB | +512bytes | +1.0KB | +3.5KB | -| net9.0 | 9.5KB | 104.5KB | +95.0KB | +8.5KB | | +512bytes | +3.0KB | -| net10.0 | 10.0KB | 82.0KB | +72.0KB | +8.5KB | | +512bytes | +3.5KB | -| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | | +1.0KB | +4.0KB | +| netstandard2.0 | 8.0KB | 364.0KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netstandard2.1 | 8.5KB | 318.0KB | +309.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 362.5KB | +354.0KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | +| net462 | 7.0KB | 366.0KB | +359.0KB | +9.5KB | +7.0KB | +9.5KB | +14.0KB | +| net47 | 7.0KB | 366.0KB | +359.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 365.0KB | +356.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | +| net472 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net48 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net481 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netcoreapp2.0 | 9.0KB | 341.5KB | +332.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.2 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.0 | 9.5KB | 315.5KB | +306.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.1 | 9.5KB | 314.0KB | +304.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| net5.0 | 9.5KB | 278.0KB | +268.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net6.0 | 10.0KB | 219.5KB | +209.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | +| net7.0 | 10.0KB | 181.0KB | +171.0KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 152.0KB | +142.5KB | +8.5KB | | +512bytes | +3.0KB | +| net9.0 | 9.5KB | 105.0KB | +95.5KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 82.5KB | +72.5KB | +8.5KB | | +512bytes | +3.5KB | +| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | +512bytes | +1.0KB | +4.0KB | ### Assembly Sizes with EmbedUntrackedSources | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 533.1KB | +525.1KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| netstandard2.1 | 8.5KB | 460.5KB | +452.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 532.7KB | +524.2KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | -| net462 | 7.0KB | 536.2KB | +529.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| net47 | 7.0KB | 535.9KB | +528.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 534.6KB | +526.1KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net472 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +8.7KB | +12.9KB | +17.9KB | -| net48 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +7.2KB | +12.9KB | +17.9KB | -| net481 | 8.5KB | 532.5KB | +524.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| netcoreapp2.0 | 9.0KB | 500.1KB | +491.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 453.6KB | +444.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 451.6KB | +442.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net5.0 | 9.5KB | 398.0KB | +388.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 319.0KB | +309.0KB | +17.7KB | +8.7KB | +1.6KB | +4.2KB | -| net7.0 | 10.0KB | 262.2KB | +252.2KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 217.3KB | +207.8KB | +16.0KB | +811bytes | +1.6KB | +4.2KB | -| net9.0 | 9.5KB | 149.7KB | +140.2KB | +16.0KB | | +1.1KB | +3.7KB | -| net10.0 | 10.0KB | 118.5KB | +108.5KB | +16.0KB | | +1.1KB | +4.2KB | -| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | | +1.6KB | +4.7KB | +| netstandard2.0 | 8.0KB | 534.0KB | +526.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netstandard2.1 | 8.5KB | 461.4KB | +452.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 533.6KB | +525.1KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | +| net462 | 7.0KB | 537.1KB | +530.1KB | +17.2KB | +8.7KB | +14.4KB | +19.4KB | +| net47 | 7.0KB | 536.8KB | +529.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net471 | 8.5KB | 535.5KB | +527.0KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | +| net472 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net48 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net481 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netcoreapp2.0 | 9.0KB | 501.0KB | +492.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.2 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.0 | 9.5KB | 454.5KB | +445.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.1 | 9.5KB | 453.0KB | +443.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| net5.0 | 9.5KB | 398.9KB | +389.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net6.0 | 10.0KB | 320.4KB | +310.4KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | +| net7.0 | 10.0KB | 263.1KB | +253.1KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 218.7KB | +209.2KB | +16.0KB | +299bytes | +1.1KB | +3.7KB | +| net9.0 | 9.5KB | 150.6KB | +141.1KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 119.4KB | +109.4KB | +16.0KB | | +1.1KB | +4.2KB | +| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | +512bytes | +1.6KB | +4.7KB | diff --git a/readme.md b/readme.md index 16bffd4e..6246fc37 100644 --- a/readme.md +++ b/readme.md @@ -13,34 +13,34 @@ The package targets `netstandard2.0` and is designed to support the following ru * `uap10` -**API count: 1052** +**API count: 1055** ### Per Target Framework | Target | APIs | | -- | -- | -| `net461` | 986 | -| `net462` | 986 | -| `net47` | 985 | -| `net471` | 984 | -| `net472` | 980 | -| `net48` | 980 | -| `net481` | 980 | -| `netstandard2.0` | 982 | -| `netstandard2.1` | 835 | -| `netcoreapp2.0` | 905 | -| `netcoreapp2.1` | 846 | -| `netcoreapp2.2` | 846 | -| `netcoreapp3.0` | 801 | -| `netcoreapp3.1` | 800 | -| `net5.0` | 672 | -| `net6.0` | 573 | -| `net7.0` | 418 | -| `net8.0` | 299 | -| `net9.0` | 205 | -| `net10.0` | 151 | +| `net461` | 991 | +| `net462` | 991 | +| `net47` | 990 | +| `net471` | 989 | +| `net472` | 985 | +| `net48` | 985 | +| `net481` | 985 | +| `netstandard2.0` | 987 | +| `netstandard2.1` | 840 | +| `netcoreapp2.0` | 910 | +| `netcoreapp2.1` | 851 | +| `netcoreapp2.2` | 851 | +| `netcoreapp3.0` | 806 | +| `netcoreapp3.1` | 805 | +| `net5.0` | 677 | +| `net6.0` | 578 | +| `net7.0` | 423 | +| `net8.0` | 304 | +| `net9.0` | 210 | +| `net10.0` | 156 | | `net11.0` | 58 | -| `uap10.0` | 972 | +| `uap10.0` | 977 | @@ -96,54 +96,54 @@ This project uses features from the newest stable SDK and C# language. As such c | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 363.5KB | +355.5KB | +7.5KB | +6.5KB | +7.5KB | +12.0KB | -| netstandard2.1 | 8.5KB | 317.5KB | +309.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net461 | 8.5KB | 362.0KB | +353.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | -| net462 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.5KB | +14.0KB | -| net47 | 7.0KB | 365.5KB | +358.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| net471 | 8.5KB | 364.5KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| net472 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +7.0KB | +8.0KB | +12.5KB | -| net48 | 8.5KB | 363.0KB | +354.5KB | +8.0KB | +5.5KB | +8.0KB | +12.5KB | -| net481 | 8.5KB | 363.5KB | +355.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | -| netcoreapp2.0 | 9.0KB | 341.0KB | +332.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.1 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp2.2 | 9.0KB | 321.0KB | +312.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.0 | 9.5KB | 315.0KB | +305.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | -| netcoreapp3.1 | 9.5KB | 313.0KB | +303.5KB | +9.0KB | +6.5KB | +9.0KB | +14.0KB | -| net5.0 | 9.5KB | 277.5KB | +268.0KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | -| net6.0 | 10.0KB | 218.5KB | +208.5KB | +10.0KB | +7.0KB | +1.0KB | +3.5KB | -| net7.0 | 10.0KB | 180.5KB | +170.5KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | -| net8.0 | 9.5KB | 151.0KB | +141.5KB | +8.5KB | +512bytes | +1.0KB | +3.5KB | -| net9.0 | 9.5KB | 104.5KB | +95.0KB | +8.5KB | | +512bytes | +3.0KB | -| net10.0 | 10.0KB | 82.0KB | +72.0KB | +8.5KB | | +512bytes | +3.5KB | -| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | | +1.0KB | +4.0KB | +| netstandard2.0 | 8.0KB | 364.0KB | +356.0KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netstandard2.1 | 8.5KB | 318.0KB | +309.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net461 | 8.5KB | 362.5KB | +354.0KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | +| net462 | 7.0KB | 366.0KB | +359.0KB | +9.5KB | +7.0KB | +9.5KB | +14.0KB | +| net47 | 7.0KB | 366.0KB | +359.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net471 | 8.5KB | 365.0KB | +356.5KB | +7.5KB | +5.5KB | +8.0KB | +12.0KB | +| net472 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net48 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| net481 | 8.5KB | 364.0KB | +355.5KB | +7.5KB | +5.0KB | +7.5KB | +12.0KB | +| netcoreapp2.0 | 9.0KB | 341.5KB | +332.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.1 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp2.2 | 9.0KB | 321.5KB | +312.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.0 | 9.5KB | 315.5KB | +306.0KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| netcoreapp3.1 | 9.5KB | 314.0KB | +304.5KB | +8.5KB | +6.5KB | +9.0KB | +13.5KB | +| net5.0 | 9.5KB | 278.0KB | +268.5KB | +9.0KB | +6.5KB | +9.0KB | +13.5KB | +| net6.0 | 10.0KB | 219.5KB | +209.5KB | +9.5KB | +6.5KB | +512bytes | +3.0KB | +| net7.0 | 10.0KB | 181.0KB | +171.0KB | +12.0KB | +8.5KB | +512bytes | +3.5KB | +| net8.0 | 9.5KB | 152.0KB | +142.5KB | +8.5KB | | +512bytes | +3.0KB | +| net9.0 | 9.5KB | 105.0KB | +95.5KB | +8.5KB | | +512bytes | +3.5KB | +| net10.0 | 10.0KB | 82.5KB | +72.5KB | +8.5KB | | +512bytes | +3.5KB | +| net11.0 | 10.0KB | 20.5KB | +10.5KB | +9.5KB | +512bytes | +1.0KB | +4.0KB | ### Assembly Sizes with EmbedUntrackedSources | | Empty Assembly | With Polyfill | Diff | Ensure | ArgumentExceptions | StringInterpolation | Nullability | |----------------|----------------|---------------|-----------|-----------|--------------------|---------------------|-------------| -| netstandard2.0 | 8.0KB | 533.1KB | +525.1KB | +15.2KB | +8.2KB | +12.4KB | +17.4KB | -| netstandard2.1 | 8.5KB | 460.5KB | +452.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net461 | 8.5KB | 532.7KB | +524.2KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | -| net462 | 7.0KB | 536.2KB | +529.2KB | +16.7KB | +8.2KB | +14.4KB | +19.4KB | -| net47 | 7.0KB | 535.9KB | +528.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| net471 | 8.5KB | 534.6KB | +526.1KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| net472 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +8.7KB | +12.9KB | +17.9KB | -| net48 | 8.5KB | 532.0KB | +523.5KB | +15.7KB | +7.2KB | +12.9KB | +17.9KB | -| net481 | 8.5KB | 532.5KB | +524.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | -| netcoreapp2.0 | 9.0KB | 500.1KB | +491.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.1 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp2.2 | 9.0KB | 467.7KB | +458.7KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.0 | 9.5KB | 453.6KB | +444.1KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | -| netcoreapp3.1 | 9.5KB | 451.6KB | +442.1KB | +16.7KB | +8.2KB | +13.9KB | +19.4KB | -| net5.0 | 9.5KB | 398.0KB | +388.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | -| net6.0 | 10.0KB | 319.0KB | +309.0KB | +17.7KB | +8.7KB | +1.6KB | +4.2KB | -| net7.0 | 10.0KB | 262.2KB | +252.2KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | -| net8.0 | 9.5KB | 217.3KB | +207.8KB | +16.0KB | +811bytes | +1.6KB | +4.2KB | -| net9.0 | 9.5KB | 149.7KB | +140.2KB | +16.0KB | | +1.1KB | +3.7KB | -| net10.0 | 10.0KB | 118.5KB | +108.5KB | +16.0KB | | +1.1KB | +4.2KB | -| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | | +1.6KB | +4.7KB | +| netstandard2.0 | 8.0KB | 534.0KB | +526.0KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netstandard2.1 | 8.5KB | 461.4KB | +452.9KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net461 | 8.5KB | 533.6KB | +525.1KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | +| net462 | 7.0KB | 537.1KB | +530.1KB | +17.2KB | +8.7KB | +14.4KB | +19.4KB | +| net47 | 7.0KB | 536.8KB | +529.8KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net471 | 8.5KB | 535.5KB | +527.0KB | +15.2KB | +7.2KB | +12.9KB | +17.4KB | +| net472 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net48 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| net481 | 8.5KB | 533.4KB | +524.9KB | +15.2KB | +6.7KB | +12.4KB | +17.4KB | +| netcoreapp2.0 | 9.0KB | 501.0KB | +492.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.1 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp2.2 | 9.0KB | 468.6KB | +459.6KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.0 | 9.5KB | 454.5KB | +445.0KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| netcoreapp3.1 | 9.5KB | 453.0KB | +443.5KB | +16.2KB | +8.2KB | +13.9KB | +18.9KB | +| net5.0 | 9.5KB | 398.9KB | +389.4KB | +16.7KB | +8.2KB | +13.9KB | +18.9KB | +| net6.0 | 10.0KB | 320.4KB | +310.4KB | +17.2KB | +8.2KB | +1.1KB | +3.7KB | +| net7.0 | 10.0KB | 263.1KB | +253.1KB | +19.6KB | +9.9KB | +1.1KB | +4.2KB | +| net8.0 | 9.5KB | 218.7KB | +209.2KB | +16.0KB | +299bytes | +1.1KB | +3.7KB | +| net9.0 | 9.5KB | 150.6KB | +141.1KB | +16.0KB | | +1.1KB | +4.2KB | +| net10.0 | 10.0KB | 119.4KB | +109.4KB | +16.0KB | | +1.1KB | +4.2KB | +| net11.0 | 10.0KB | 30.4KB | +20.4KB | +17.0KB | +512bytes | +1.6KB | +4.7KB | @@ -698,6 +698,13 @@ The class `Polyfill` includes the following extension methods: * `void WriteSingleLittleEndian(Span, float)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.buffers.binary.binaryprimitives.writesinglelittleendian?view=net-11.0) +#### BitArray + + * `bool HasAllSet()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.hasallset?view=net-11.0) + * `bool HasAnySet()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.hasanyset?view=net-11.0) + * `int PopCount()` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.popcount?view=net-11.0) + + #### Boolean * `bool TryFormat(Span, int)` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.boolean.tryformat?view=net-11.0) @@ -2388,7 +2395,7 @@ void ObjectDisposedExceptionExample(bool isDisposed) ObjectDisposedException.ThrowIf(isDisposed, typeof(Consume)); } ``` -snippet source | anchor +snippet source | anchor @@ -2407,7 +2414,7 @@ void EnsureExample(Order order, Customer customer, string customerId, string ema this.quantity = Ensure.NotNegativeOrZero(quantity); } ``` -snippet source | anchor +snippet source | anchor diff --git a/src/Consume/Consume.cs b/src/Consume/Consume.cs index 13f20ce3..3c14b5e4 100644 --- a/src/Consume/Consume.cs +++ b/src/Consume/Consume.cs @@ -557,6 +557,14 @@ void BitConverter_Methods() var ulongFromDouble = BitConverter.DoubleToUInt64Bits(1.0); } + void BitArray_Methods() + { + var bitArray = new BitArray(8, true); + bool hasAllSet = bitArray.HasAllSet(); + bool hasAnySet = bitArray.HasAnySet(); + int popCount = bitArray.PopCount(); + } + void BinaryPrimitives_Methods() { var buffer = new byte[8]; diff --git a/src/Polyfill/Polyfill_BitArray.cs b/src/Polyfill/Polyfill_BitArray.cs new file mode 100644 index 00000000..129262a8 --- /dev/null +++ b/src/Polyfill/Polyfill_BitArray.cs @@ -0,0 +1,66 @@ +#if !NET11_0_OR_GREATER + +namespace Polyfills; + +using System.Collections; + +static partial class Polyfill +{ +#if !NET8_0_OR_GREATER + + /// + /// Determines whether all bits in the are set to . + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.hasallset?view=net-11.0 + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + + return true; + } + + /// + /// Determines whether any bit in the is set to . + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.hasanyset?view=net-11.0 + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + + return false; + } + +#endif + + /// + /// Returns the number of bits set to in the . + /// + //Link: https://learn.microsoft.com/en-us/dotnet/api/system.collections.bitarray.popcount?view=net-11.0 + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + + return count; + } +} + +#endif diff --git a/src/Split/net10.0/Polyfill_BitArray.cs b/src/Split/net10.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..537b044d --- /dev/null +++ b/src/Split/net10.0/Polyfill_BitArray.cs @@ -0,0 +1,22 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net461/Polyfill_BitArray.cs b/src/Split/net461/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net461/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net462/Polyfill_BitArray.cs b/src/Split/net462/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net462/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net47/Polyfill_BitArray.cs b/src/Split/net47/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net47/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net471/Polyfill_BitArray.cs b/src/Split/net471/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net471/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net472/Polyfill_BitArray.cs b/src/Split/net472/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net472/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net48/Polyfill_BitArray.cs b/src/Split/net48/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net48/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net481/Polyfill_BitArray.cs b/src/Split/net481/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net481/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net5.0/Polyfill_BitArray.cs b/src/Split/net5.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net5.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net6.0/Polyfill_BitArray.cs b/src/Split/net6.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net6.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net7.0/Polyfill_BitArray.cs b/src/Split/net7.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/net7.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net8.0/Polyfill_BitArray.cs b/src/Split/net8.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..537b044d --- /dev/null +++ b/src/Split/net8.0/Polyfill_BitArray.cs @@ -0,0 +1,22 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/net9.0/Polyfill_BitArray.cs b/src/Split/net9.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..537b044d --- /dev/null +++ b/src/Split/net9.0/Polyfill_BitArray.cs @@ -0,0 +1,22 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netcoreapp2.0/Polyfill_BitArray.cs b/src/Split/netcoreapp2.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netcoreapp2.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netcoreapp2.1/Polyfill_BitArray.cs b/src/Split/netcoreapp2.1/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netcoreapp2.1/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netcoreapp2.2/Polyfill_BitArray.cs b/src/Split/netcoreapp2.2/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netcoreapp2.2/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netcoreapp3.0/Polyfill_BitArray.cs b/src/Split/netcoreapp3.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netcoreapp3.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netcoreapp3.1/Polyfill_BitArray.cs b/src/Split/netcoreapp3.1/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netcoreapp3.1/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netstandard2.0/Polyfill_BitArray.cs b/src/Split/netstandard2.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netstandard2.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/netstandard2.1/Polyfill_BitArray.cs b/src/Split/netstandard2.1/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/netstandard2.1/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Split/uap10.0/Polyfill_BitArray.cs b/src/Split/uap10.0/Polyfill_BitArray.cs new file mode 100644 index 00000000..560bba8f --- /dev/null +++ b/src/Split/uap10.0/Polyfill_BitArray.cs @@ -0,0 +1,50 @@ +// +#pragma warning disable +namespace Polyfills; +using System.Collections; +static partial class Polyfill +{ + /// + /// Determines whether all bits in the are set to . + /// + public static bool HasAllSet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (!target[index]) + { + return false; + } + } + return true; + } + /// + /// Determines whether any bit in the is set to . + /// + public static bool HasAnySet(this BitArray target) + { + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + return true; + } + } + return false; + } + /// + /// Returns the number of bits set to in the . + /// + public static int PopCount(this BitArray target) + { + var count = 0; + for (var index = 0; index < target.Length; index++) + { + if (target[index]) + { + count++; + } + } + return count; + } +} diff --git a/src/Tests/PolyfillTests_BitArray.cs b/src/Tests/PolyfillTests_BitArray.cs new file mode 100644 index 00000000..4619f8ed --- /dev/null +++ b/src/Tests/PolyfillTests_BitArray.cs @@ -0,0 +1,79 @@ +using System.Collections; + +partial class PolyfillTests +{ + [Test] + public async Task BitArray_Empty() + { + var target = new BitArray(0); + // all set is vacuously true for an empty BitArray + await Assert.That(target.HasAllSet()).IsTrue(); + await Assert.That(target.HasAnySet()).IsFalse(); + await Assert.That(target.PopCount()).IsEqualTo(0); + } + + [Test] + public async Task BitArray_AllClear() + { + var target = new BitArray(8); + await Assert.That(target.HasAllSet()).IsFalse(); + await Assert.That(target.HasAnySet()).IsFalse(); + await Assert.That(target.PopCount()).IsEqualTo(0); + } + + [Test] + public async Task BitArray_AllSet() + { + var target = new BitArray(8, true); + await Assert.That(target.HasAllSet()).IsTrue(); + await Assert.That(target.HasAnySet()).IsTrue(); + await Assert.That(target.PopCount()).IsEqualTo(8); + } + + [Test] + public async Task BitArray_Mixed() + { + var target = new BitArray(8) + { + [3] = true, + [7] = true + }; + await Assert.That(target.HasAllSet()).IsFalse(); + await Assert.That(target.HasAnySet()).IsTrue(); + await Assert.That(target.PopCount()).IsEqualTo(2); + } + + [Test] + public async Task BitArray_Single() + { + var clear = new BitArray(1); + await Assert.That(clear.HasAllSet()).IsFalse(); + await Assert.That(clear.HasAnySet()).IsFalse(); + await Assert.That(clear.PopCount()).IsEqualTo(0); + + var set = new BitArray(1, true); + await Assert.That(set.HasAllSet()).IsTrue(); + await Assert.That(set.HasAnySet()).IsTrue(); + await Assert.That(set.PopCount()).IsEqualTo(1); + } + + // the last word is only partly used, so the unused high bits must not be counted + [Test] + [Arguments(31)] + [Arguments(32)] + [Arguments(33)] + [Arguments(64)] + [Arguments(100)] + public async Task BitArray_WordBoundaries(int length) + { + var target = new BitArray(length, true); + await Assert.That(target.HasAllSet()).IsTrue(); + await Assert.That(target.HasAnySet()).IsTrue(); + await Assert.That(target.PopCount()).IsEqualTo(length); + + target[length - 1] = false; + await Assert.That(target.HasAllSet()).IsFalse(); + await Assert.That(target.HasAnySet()).IsTrue(); + await Assert.That(target.PopCount()).IsEqualTo(length - 1); + } +}