/*
        /**********************************************************
        /* Standard methods
        /**********************************************************
        */
        /*
        @Override
        public String toString()
        {
        StringBuilder sb = new StringBuilder();
        sb.append("[BytesToNameCanonicalizer, size: ");
        sb.append(_count);
        sb.append('/');
        sb.append(_mainHash.length);
        sb.append(", ");
        sb.append(_collCount);
        sb.append(" coll; avg length: ");

        // Average length: minimum of 1 for all (1 == primary hit);
        // and then 1 per each traversal for collisions/buckets
        //int maxDist = 1;
        int pathCount = _count;
        for (int i = 0; i < _collEnd; ++i) {
        int spillLen = _collList[i].length();
        for (int j = 1; j <= spillLen; ++j) {
        pathCount += j;
        }
        }
        double avgLength;

        if (_count == 0) {
        avgLength = 0.0;
        } else {
        avgLength = (double) pathCount / (double) _count;
        }
        // let's round up a bit (two 2 decimal places)
        //avgLength -= (avgLength % 0.01);

        sb.append(avgLength);
        sb.append(']');
        return sb.toString();
        }
        */
        /*
        /**********************************************************
        /* Internal methods
        /**********************************************************
        */
        private void _addSymbol(int hash, com.fasterxml.jackson.core.sym.Name symbol)
        {
            if (_hashShared)
            {
                // always have to modify main entry
                unshareMain();
            }
            // First, do we need to rehash?
            if (_needRehash)
            {
                rehash();
            }
            ++_count;
            /* Ok, enough about set up: now we need to find the slot to add
            * symbol in:
            */
            int ix = (hash & _hashMask);
            if (_mainNames[ix] == null)
            {
                // primary empty?
                _hash[ix] = (hash << 8);
                if (_namesShared)
                {
                    unshareNames();
                }
                _mainNames[ix] = symbol;
            }
            else
            {
                // nope, it's a collision, need to spill over
                /* How about spill-over area... do we already know the bucket
                * (is the case if it's not the first collision)
                */
                if (_collListShared)
                {
                    unshareCollision();
                }
                // also allocates if list was null
                ++_collCount;
                int entryValue = _hash[ix];
                int bucket = entryValue & unchecked((int)(0xFF));
                if (bucket == 0)
                {
                    // first spill over?
                    if (_collEnd <= LAST_VALID_BUCKET)
                    {
                        // yup, still unshared bucket
                        bucket = _collEnd;
                        ++_collEnd;
                        // need to expand?
                        if (bucket >= _collList.Length)
                        {
                            expandCollision();
                        }
                    }
                    else
                    {
                        // nope, have to share... let's find shortest?
                        bucket = findBestBucket();
                    }
                    // Need to mark the entry... and the spill index is 1-based
                    _hash[ix] = (entryValue & ~unchecked((int)(0xFF))) | (bucket + 1);
                }
                else
                {
                    --bucket;
                }
                // 1-based index in value
                // And then just need to link the new bucket entry in
                com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket newB = new com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket
                    (symbol, _collList[bucket]);
                int collLen = newB.length;
                if (collLen > MAX_COLL_CHAIN_LENGTH)
                {
                    /* 23-May-2014, tatu: Instead of throwing an exception right away, let's handle
                    *   in bit smarter way.
                    */
                    _handleSpillOverflow(bucket, newB);
                }
                else
                {
                    _collList[bucket] = newB;
                    // but, be careful wrt attacks
                    _longestCollisionList = System.Math.max(newB.length, _longestCollisionList);
                }
            }
            {
                /* Ok. Now, do we need a rehash next time? Need to have at least
                * 50% fill rate no matter what:
                */
                int hashSize = _hash.Length;
                if (_count > (hashSize >> 1))
                {
                    int hashQuarter = (hashSize >> 2);
                    /* And either strictly above 75% (the usual) or
                    * just 50%, and collision count >= 25% of total hash size
                    */
                    if (_count > (hashSize - hashQuarter))
                    {
                        _needRehash = true;
                    }
                    else
                    {
                        if (_collCount >= hashQuarter)
                        {
                            _needRehash = true;
                        }
                    }
                }
            }
        }
 internal Bucket(com.fasterxml.jackson.core.sym.Name name, com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket
     next)
 {
     this.name = name;
     this.next = next;
     length = (next == null) ? 1 : next.length + 1;
     hash = name.GetHashCode();
 }
 private void rehash()
 {
     _needRehash = false;
     // Note: since we'll make copies, no need to unshare, can just mark as such:
     _namesShared = false;
     /* And then we can first deal with the main hash area. Since we
     * are expanding linearly (double up), we know there'll be no
     * collisions during this phase.
     */
     int[] oldMainHash = _hash;
     int len = oldMainHash.Length;
     int newLen = len + len;
     /* 13-Mar-2010, tatu: Let's guard against OOME that could be caused by
     *    large documents with unique (or mostly so) names
     */
     if (newLen > MAX_T_SIZE)
     {
         nukeSymbols();
         return;
     }
     _hash = new int[newLen];
     _hashMask = (newLen - 1);
     com.fasterxml.jackson.core.sym.Name[] oldNames = _mainNames;
     _mainNames = new com.fasterxml.jackson.core.sym.Name[newLen];
     int symbolsSeen = 0;
     // let's do a sanity check
     for (int i = 0; i < len; ++i)
     {
         com.fasterxml.jackson.core.sym.Name symbol = oldNames[i];
         if (symbol != null)
         {
             ++symbolsSeen;
             int hash = symbol.GetHashCode();
             int ix = (hash & _hashMask);
             _mainNames[ix] = symbol;
             _hash[ix] = hash << 8;
         }
     }
     // will clear spill index
     /* And then the spill area. This may cause collisions, although
     * not necessarily as many as there were earlier. Let's allocate
     * same amount of space, however
     */
     int oldEnd = _collEnd;
     if (oldEnd == 0)
     {
         // no prior collisions...
         _longestCollisionList = 0;
         return;
     }
     _collCount = 0;
     _collEnd = 0;
     _collListShared = false;
     int maxColl = 0;
     com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket[] oldBuckets = _collList;
     _collList = new com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket[oldBuckets
         .Length];
     for (int i_1 = 0; i_1 < oldEnd; ++i_1)
     {
         for (com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket curr = oldBuckets
             [i_1]; curr != null; curr = curr.next)
         {
             ++symbolsSeen;
             com.fasterxml.jackson.core.sym.Name symbol = curr.name;
             int hash = symbol.GetHashCode();
             int ix = (hash & _hashMask);
             int val = _hash[ix];
             if (_mainNames[ix] == null)
             {
                 // no primary entry?
                 _hash[ix] = (hash << 8);
                 _mainNames[ix] = symbol;
             }
             else
             {
                 // nope, it's a collision, need to spill over
                 ++_collCount;
                 int bucket = val & unchecked((int)(0xFF));
                 if (bucket == 0)
                 {
                     // first spill over?
                     if (_collEnd <= LAST_VALID_BUCKET)
                     {
                         // yup, still unshared bucket
                         bucket = _collEnd;
                         ++_collEnd;
                         // need to expand?
                         if (bucket >= _collList.Length)
                         {
                             expandCollision();
                         }
                     }
                     else
                     {
                         // nope, have to share... let's find shortest?
                         bucket = findBestBucket();
                     }
                     // Need to mark the entry... and the spill index is 1-based
                     _hash[ix] = (val & ~unchecked((int)(0xFF))) | (bucket + 1);
                 }
                 else
                 {
                     --bucket;
                 }
                 // 1-based index in value
                 // And then just need to link the new bucket entry in
                 com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket newB = new com.fasterxml.jackson.core.sym.BytesToNameCanonicalizer.Bucket
                     (symbol, _collList[bucket]);
                 _collList[bucket] = newB;
                 maxColl = System.Math.max(maxColl, newB.length);
             }
         }
     }
     // for (... buckets in the chain ...)
     // for (... list of bucket heads ... )
     _longestCollisionList = maxColl;
     if (symbolsSeen != _count)
     {
         // sanity check
         throw new Sharpen.RuntimeException("Internal error: count after rehash " + symbolsSeen
              + "; should be " + _count);
     }
 }