<commit_before>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CSharp.RuntimeBinder.Syntax
{
    internal sealed class NameTable
    {
        private sealed class Entry
        {
            public readonly Name Name;
            public readonly int HashCode;
            public Entry Next;

            public Entry(Name name, int hashCode, Entry next)
            {
                Name = name;
                HashCode = hashCode;
                Next = next;
            }
        }

        private Entry[] _entries;
        private int _count;
        private int _mask;
        private readonly int _hashCodeRandomizer;

        internal NameTable()
        {
            _mask = 31;
            _entries = new Entry[_mask + 1];
            //hashCodeRandomizer = Environment.TickCount;
            _hashCodeRandomizer = 0;
        }

        public Name Add(string key)
        {
            int hashCode = ComputeHashCode(key);
            for (Entry e = _entries[hashCode & _mask]; e != null; e = e.Next)
            {
                if (e.HashCode == hashCode && e.Name.Text.Equals(key))
                {
                    return e.Name;
                }
            }

            return AddEntry(new Name(key), hashCode);
        }

        internal void Add(Name name)
        {
            int hashCode = ComputeHashCode(name.Text);
            // make sure it doesn't already exist
            for (Entry e = _entries[hashCode & _mask]; e != null; e = e.Next)
            {
                if (e.HashCode == hashCode && e.Name.Text.Equals(name.Text))
                {
                    throw Error.InternalCompilerError();
                }
            }

            AddEntry(name, hashCode);
        }

        public Name Lookup(string key)
        {
            int hashCode = ComputeHashCode(key);
            for (Entry e = _entries[hashCode & _mask]; e != null; e = e.Next)
            {
                if (e.HashCode == hashCode && e.Name.Text.Equals(key))
                {
                    return e.Name;
                }
            }

            return null;
        }

        private int ComputeHashCode(string key)
        {
            int hashCode, len = key.Length;

            unchecked
            {
                hashCode = len + _hashCodeRandomizer;
                // use key.Length to eliminate the range check
                for (int i = 0; i < key.Length; i++)
                {
                    hashCode += (hashCode << 7) ^ key[i];
                }
                // mix it a bit more
                hashCode -= hashCode >> 17;
                hashCode -= hashCode >> 11;
                hashCode -= hashCode >> 5;
            }

            return hashCode;
        }

        private Name AddEntry(Name name, int hashCode)
        {
            int index = hashCode & _mask;
            Entry e = new Entry(name, hashCode, _entries[index]);
            _entries[index] = e;
            if (_count++ == _mask)
            {<commit_msg>Remove _hashCodeRandomizer.<commit_after>// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace Microsoft.CSharp.RuntimeBinder.Syntax
{
    internal sealed class NameTable
    {
        private sealed class Entry
        {
            public readonly Name Name;
            public readonly int HashCode;
            public Entry Next;

            public Entry(Name name, int hashCode, Entry next)
            {
                Name = name;
                HashCode = hashCode;
                Next = next;
            }
        }

        private Entry[] _entries;
        private int _count;
        private int _mask;

        internal NameTable()
        {
            _mask = 31;
            _entries = new Entry[_mask + 1];
        }

        public Name Add(string key)
        {
            int hashCode = ComputeHashCode(key);
            for (Entry e = _entries[hashCode & _mask]; e != null; e = e.Next)
            {
                if (e.HashCode == hashCode && e.Name.Text.Equals(key))
                {
                    return e.Name;
                }
            }

            return AddEntry(new Name(key), hashCode);
        }

        internal void Add(Name name)
        {
            int hashCode = ComputeHashCode(name.Text);
            // make sure it doesn't already exist
            for (Entry e = _entries[hashCode & _mask]; e != null; e = e.Next)
            {
                if (e.HashCode == hashCode && e.Name.Text.Equals(name.Text))
                {
                    throw Error.InternalCompilerError();
                }
            }

            AddEntry(name, hashCode);
        }

        public Name Lookup(string key)
        {
            int hashCode = ComputeHashCode(key);
            for (Entry e = _entries[hashCode & _mask]; e != null; e = e.Next)
            {
                if (e.HashCode == hashCode && e.Name.Text.Equals(key))
                {
                    return e.Name;
                }
            }

            return null;
        }

        private int ComputeHashCode(string key)
        {
            int hashCode, len = key.Length;

            unchecked
            {
                hashCode = len;
                // use key.Length to eliminate the range check
                for (int i = 0; i < key.Length; i++)
                {
                    hashCode += (hashCode << 7) ^ key[i];
                }
                // mix it a bit more
                hashCode -= hashCode >> 17;
                hashCode -= hashCode >> 11;
                hashCode -= hashCode >> 5;
            }

            return hashCode;
        }

        private Name AddEntry(Name name, int hashCode)
        {
            int index = hashCode & _mask;
            Entry e = new Entry(name, hashCode, _entries[index]);
            _entries[index] = e;
            if (_count++ == _mask)
            {
{'fraction_non_alphanumeric': 0.0866484135931712, 'fraction_numerical': 0.0033821871476888386, 'mean_word_length': 1.1943462897526502, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1893061', 'n_tokens_mistral': 1637, 'n_tokens_neox': 1527, 'n_words': 472}