< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 29
Coverable lines: 29
Total lines: 82
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 12
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
CreateInverse()0%220%
Set(...)100%110%
Contains256(...)0%220%
Contains(...)100%110%
ContainsUnchecked(...)100%110%
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        {
 016            BitVector256 inverse = default;
 17
 018            for (int i = 0; i < 8; i++)
 19            {
 020                inverse._values[i] = ~_values[i];
 21            }
 22
 023            return inverse;
 24        }
 25
 26        public void Set(int c)
 27        {
 028            Debug.Assert(c < 256);
 029            uint offset = (uint)(c >> 5);
 030            uint significantBit = 1u << c;
 031            _values[(int)offset] |= significantBit;
 032        }
 33
 34        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 35        public readonly bool Contains256(char c) =>
 036            c < 256 && ContainsUnchecked(c);
 37
 38        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 39        public readonly bool Contains(byte b) =>
 040            ContainsUnchecked(b);
 41
 42        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 43        private readonly bool ContainsUnchecked(int b)
 44        {
 045            Debug.Assert(b < 256);
 046            uint offset = (uint)(b >> 5);
 047            uint significantBit = 1u << b;
 048            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