Пример #1
0
        internal static ulong HashWordIgnoreCaseUnderscoreIsSpace(ReadOnlySpan <char> word, ulong lexID, ulong uniqueId)
        {
            unchecked
            {
                //Implementation of Fowler/Noll/Vo (https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function), also used by the Roslyn compiler: https://github.com/dotnet/roslyn/blob/master/src/Compilers/Core/Portable/InternalUtilities/Hash.cs
                const ulong fnv_prime        = 1099511628211LU;
                const ulong fnv_offset_basis = 0xcbf29ce484222325;
                ulong       hash             = fnv_offset_basis;
                for (int i = 0; i < word.Length; i++)
                {
                    var c = word[i];

                    if (c == '_')
                    {
                        c = ' ';
                    }

                    if (char.IsUpper(c))
                    {
                        c = char.ToLowerInvariant(c);
                    }

                    hash = (hash ^ c) * fnv_prime;
                }

                return(Hashes.Combine(Hashes.Combine(hash, lexID + 1UL), uniqueId + 1UL));
            }
        }