< Summary

Class:Azure.Core.Http.Multipart.HashCodeCombiner
Assembly:Azure.Storage.Blobs.Batch
File(s):C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\HashCodeCombiner.cs
Covered lines:0
Uncovered lines:24
Coverable lines:24
Total lines:86
Line coverage:0% (0 of 24)
Covered branches:0
Total branches:10
Branch coverage:0% (0 of 10)

Metrics

MethodCyclomatic complexity Line coverage Branch coverage
get_CombinedHash()-0%100%
.ctor(...)-0%100%
Add(...)-0%0%
op_Implicit(...)-0%100%
Add(...)-0%100%
Add(...)-0%0%
Add(...)-0%0%
Add(...)-0%0%
Start()-0%100%

File(s)

C:\Git\azure-sdk-for-net\sdk\storage\Azure.Storage.Blobs.Batch\src\Shared\HashCodeCombiner.cs

#LineLine coverage
 1// Copyright (c) Microsoft Corporation. All rights reserved.
 2// Licensed under the MIT License.
 3
 4// Copied from https://github.com/aspnet/Extensions/tree/master/src/Shared/src/HashCodeCombiner
 5
 6using System.Collections;
 7using System.Collections.Generic;
 8using System.Runtime.CompilerServices;
 9
 10namespace Azure.Core.Http.Multipart
 11{
 12    internal struct HashCodeCombiner
 13    {
 14        private long _combinedHash64;
 15
 16        public int CombinedHash
 17        {
 18            [MethodImpl(MethodImplOptions.AggressiveInlining)]
 019            get { return _combinedHash64.GetHashCode(); }
 20        }
 21
 22        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 23        private HashCodeCombiner(long seed)
 24        {
 025            _combinedHash64 = seed;
 026        }
 27
 28        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 29        public void Add(IEnumerable e)
 30        {
 031            if (e == null)
 32            {
 033                Add(0);
 34            }
 35            else
 36            {
 037                var count = 0;
 038                foreach (object o in e)
 39                {
 040                    Add(o);
 041                    count++;
 42                }
 043                Add(count);
 44            }
 045        }
 46
 47        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 48        public static implicit operator int(HashCodeCombiner self)
 49        {
 050            return self.CombinedHash;
 51        }
 52
 53        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 54        public void Add(int i)
 55        {
 056            _combinedHash64 = ((_combinedHash64 << 5) + _combinedHash64) ^ i;
 057        }
 58
 59        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 60        public void Add(string s)
 61        {
 062            var hashCode = (s != null) ? s.GetHashCode() : 0;
 063            Add(hashCode);
 064        }
 65
 66        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 67        public void Add(object o)
 68        {
 069            var hashCode = (o != null) ? o.GetHashCode() : 0;
 070            Add(hashCode);
 071        }
 72
 73        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 74        public void Add<TValue>(TValue value, IEqualityComparer<TValue> comparer)
 75        {
 076            var hashCode = value != null ? comparer.GetHashCode(value) : 0;
 077            Add(hashCode);
 078        }
 79
 80        [MethodImpl(MethodImplOptions.AggressiveInlining)]
 81        public static HashCodeCombiner Start()
 82        {
 083            return new HashCodeCombiner(0x1505L);
 84        }
 85    }
 86}