// master ctor public HashTable(int initialCapacity) { if (initialCapacity < 1) { throw new ArgumentOutOfRangeException("Given size is less than 1"); } _array = new HashTableArray <TKey, TValue>(initialCapacity); // Increasing the size of the array _maxItemsAtCurrentSize = (int)(initialCapacity * _fillFactor) + 1; }
public void Add(TKey key, TValue value) { if (_count >= _maxItemsAtCurrentSize) { // Increasing the capacity HashTableArray <TKey, TValue> largerArray = new HashTableArray <TKey, TValue>(_array.Capacity * 2); // copying the values to the new array foreach (HashTableNodePair <TKey, TValue> node in _array.Items) { largerArray.Add(node.Key, node.Value); } _array = largerArray; _maxItemsAtCurrentSize = (int)(_array.Capacity * _fillFactor) + 1; } _array.Add(key, value); _count++; }