コード例 #1
0
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode(byte[] obj)
        {
            // Null
            if (obj is null)
            {
                return(0);
            }

            // Empty
            if (obj.Length == 0)
            {
                return(ByteHashCode.Empty);
            }

            // Calculate on full length
            Span <byte> span = obj.AsSpan();

            // Calculate on prefix
            if (HashCodeFidelity > 0 && obj.Length > HashCodeFidelity)
            {
                span = span.Slice(0, HashCodeFidelity);
            }

            var hc = ByteHashCode.Combine(span);

            return(hc);
        }
コード例 #2
0
        /// <summary>
        /// Returns a hash code for this instance.
        /// </summary>
        /// <param name="obj">The object.</param>
        /// <returns>
        /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
        /// </returns>
        public override int GetHashCode(ReadOnlyMemory <byte> obj)
        {
            // Empty
            if (obj.Length == 0)
            {
                return(ByteHashCode.Empty);
            }

            // Calculate on full length
            ReadOnlySpan <byte> span = obj.Span;

            // Calculate on prefix
            if (HashCodeFidelity > 0 && obj.Length > HashCodeFidelity)
            {
                span = span.Slice(0, HashCodeFidelity);
            }

            int hc = ByteHashCode.Combine(span);

            return(hc);
        }