Exemple #1
0
        /// <summary>
        /// Hashes the specified Span.
        /// </summary>
        public static int GetHashCode <T>(this ReadOnlySpan <T> values, Func <T, int> converter)
        {
            if (values.Length == 0)
            {
                return(0);
            }

            // It is hacky to make these values public, but until HashCodeHelper is a .NET Core project,
            // it's too inefficient to implement this any other way (and not acceptable to duplicate
            // the Fold implementation).
            int hash = HashCodeHelper.Fnv1Basis32;

            foreach (T value in values)
            {
                hash = HashCodeHelper.Fold(hash, converter(value));
            }

            return(hash);
        }