< Summary

Line coverage
0%
Covered lines: 0
Uncovered lines: 14
Coverable lines: 14
Total lines: 51
Line coverage: 0%
Branch coverage
0%
Covered branches: 0
Total branches: 2
Branch coverage: 0%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Cyclomatic complexity NPath complexity Sequence coverage
Combine(...)100%110%
Combine(...)100%110%
GetFNVHashCode(...)0%220%

File(s)

https://raw.githubusercontent.com/dotnet/runtime/811a7eabb75c42db53440e8ba3f60c07511cfd1f/src/libraries/System.Reflection.Metadata/src/System/Reflection/Internal/Utilities/Hash.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.Immutable;
 5
 6namespace System.Reflection.Internal
 7{
 8    internal static class Hash
 9    {
 10        internal static int Combine(int newKey, int currentKey)
 011        {
 012            return unchecked((currentKey * (int)0xA5555529) + newKey);
 013        }
 14
 15        internal static int Combine(uint newKey, int currentKey)
 016        {
 017            return unchecked((currentKey * (int)0xA5555529) + (int)newKey);
 018        }
 19
 20        /// <summary>
 21        /// The offset bias value used in the FNV-1a algorithm
 22        /// See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
 23        /// </summary>
 24        internal const int FnvOffsetBias = unchecked((int)2166136261);
 25
 26        /// <summary>
 27        /// The generative factor used in the FNV-1a algorithm
 28        /// See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
 29        /// </summary>
 30        internal const int FnvPrime = 16777619;
 31
 32        /// <summary>
 33        /// Compute the FNV-1a hash of a sequence of bytes
 34        /// See http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
 35        /// </summary>
 36        /// <param name="data">The sequence of bytes</param>
 37        /// <returns>The FNV-1a hash of <paramref name="data"/></returns>
 38        internal static int GetFNVHashCode(ReadOnlySpan<byte> data)
 039        {
 040            int hashCode = Hash.FnvOffsetBias;
 41
 042            for (int i = 0; i < data.Length; i++)
 043            {
 044                hashCode = unchecked((hashCode ^ data[i]) * Hash.FnvPrime);
 045            }
 46
 047            return hashCode;
 048        }
 49    }
 50}
 51