コード例 #1
0
        private DictionaryBucket[] Rehashing(string key)
        {
            sizeOfArray = _array.Length * growthCoefficient;

            DictionaryBucket[] newArray = new DictionaryBucket[sizeOfArray];
            GetIndex(key);

            for (int i = 0; i < _array.Length; i++)
            {
                int keyHash  = _array[i].key.GetHashCode();
                int newIndex = Math.Abs(keyHash % sizeOfArray);

                while (newArray[newIndex] != null)
                {
                    newIndex++;
                }

                if (newIndex == sizeOfArray)
                {
                    for (int j = 0; i < _array.Length; i++)
                    {
                        if (_array[i] == null)
                        {
                            newIndex = i;
                        }
                    }
                }
                newArray[newIndex] = _array[i];
            }

            _array = newArray;

            return(_array);
        }
コード例 #2
0
        private void AddToArray(string key, string value)
        {
            DictionaryBucket dictionaryBucket = new DictionaryBucket();

            dictionaryBucket.key   = key;
            dictionaryBucket.value = value;

            GetIndex(key);

            if (_array[index] == null)
            {
                _array[index] = dictionaryBucket;
            }
            else
            {
                GetIndexIfValueIsNotNull(key);

                _array[index] = dictionaryBucket;
            }
        }
コード例 #3
0
 public Dictionary()
 {
     DictionaryBucket[] newArray = new DictionaryBucket[sizeOfArray];
     _array = newArray;
 }