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); }
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; } }
public Dictionary() { DictionaryBucket[] newArray = new DictionaryBucket[sizeOfArray]; _array = newArray; }