< Summary

Line coverage
51%
Covered lines: 15
Uncovered lines: 14
Coverable lines: 29
Total lines: 82
Line coverage: 51.7%
Branch coverage
33%
Covered branches: 4
Total branches: 12
Branch coverage: 33.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CreateInverse()100%22100%
Set(...)100%11100%
Contains256(...)100%22100%
Contains(...)100%11100%
ContainsUnchecked(...)100%11100%
GetCharValues()0%440%
GetByteValues()0%440%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Private.CoreLib/src/System/SearchValues/BitVector256.cs

#LineLine coverage
 1// Licensed to the .NET Foundation under one or more agreements.
 2// The .NET Foundation licenses this file to you under the MIT license.
 3
 4using System.Collections.Generic;
 5using System.Diagnostics;
 6using System.Runtime.CompilerServices;
 7
 8namespace System.Buffers
 9{
 10    internal struct BitVector256
 11    {
 12        private InlineArray8<uint> _values;
 13
 14        public readonly BitVector256 CreateInverse()
 15        {
 139516            BitVector256 inverse = default;
 17
 2511018            for (int i = 0; i < 8; i++)
 19            {
 1116020                inverse._values[i] = ~_values[i];
 21            }
 22
 139523            return inverse;
 24        }
 25
 26        public void Set(int c)
 27        {
 60472328            Debug.Assert(c < 256);
 60472329            uint offset = (uint)(c >> 5);
 60472330            uint significantBit = 1u << c;
 60472331            _values[(int)offset] |= significantBit;
 60472332        }
 33
 34        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 35        public readonly bool Contains256(char c) =>
 23158736            c < 256 && ContainsUnchecked(c);
 37
 38        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 39        public readonly bool Contains(byte b) =>
 126141740            ContainsUnchecked(b);
 41
 42        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 43        private readonly bool ContainsUnchecked(int b)
 44        {
 132174145            Debug.Assert(b < 256);
 132174146            uint offset = (uint)(b >> 5);
 132174147            uint significantBit = 1u << b;
 132174148            return (_values[(int)offset] & significantBit) != 0;
 49        }
 50
 51        public readonly unsafe char[] GetCharValues()
 52        {
 053            Span<char> chars = stackalloc char[256];
 054            int size = 0;
 055            for (int i = 0; i < 256; i++)
 56            {
 057                if (ContainsUnchecked(i))
 58                {
 059                    chars[size] = (char)i;
 060                    size++;
 61                }
 62            }
 063            return chars.Slice(0, size).ToArray();
 64        }
 65
 66        public readonly unsafe byte[] GetByteValues()
 67        {
 068            Span<byte> bytes = stackalloc byte[256];
 069            int size = 0;
 070            for (int i = 0; i < 256; i++)
 71            {
 072                if (ContainsUnchecked(i))
 73                {
 074                    bytes[size] = (byte)i;
 075                    size++;
 76                }
 77            }
 078            return bytes.Slice(0, size).ToArray();
 79        }
 80    }
 81}
 82