//calling add first checks if there if count is greater than max allowed //if count is bigger, create a new hashtablearray of double the size //for all habletablearray items (hashtablenodes) add it to bigger array. //set new bigger array at array and increase maxsize //if it isn't all hashtablearray's add function public void Add(TKey key, TValue value) { //you don't necessary have to increase the size of the array //could comment this out if you know a good size for hashtable where it would be best set at if (_count >= _maxItemsAtCurrentSize) { HashTableArray <TKey, TValue> largerArray = new HashTableArray <TKey, TValue>(_arrayClass.Capacity * 2); //uses hashtablearray's ienum //seems like a lot of layers //yielding many layers of ienum to get pairs //which ultimating calls add use each pairs key and value foreach (HashTableNodePair <TKey, TValue> node in _arrayClass.Items) { largerArray.Add(node.Key, node.Value); } //set and resize _arrayClass = largerArray; _maxItemsAtCurrentSize = (int)(_arrayClass.Capacity * _fillFactor) + 1; } _arrayClass.Add(key, value); _count++; }
public HashTable(int initialCapacity) { if (initialCapacity < 1) { throw new ArgumentOutOfRangeException("initialCapacity"); } _array = new HashTableArray <TKey, TValue>(initialCapacity); _maxItemsAtCurrentSize = (int)(initialCapacity * _fillFactor) + 1; }
public HashTable(int initialCapacity) { if (initialCapacity < 1) { throw new ArgumentException("Give a valid capacity!"); } else { array = new HashTableArray <TKey, TValue>(initialCapacity); } }
/// <summary> /// Constructs a hash table with the specified capacity /// </summary> /// <param name="initialCapacity"></param> public HashTable(int initialCapacity) { if (initialCapacity < 1) { throw new ArgumentOutOfRangeException("initial capacity is too small"); } _array = new HashTableArray <TKey, TValue>(initialCapacity); //when the count exceeds this value, the next Add operation will cause the array to grow _maxItemsAtCurrentSize = (int)(initialCapacity * _fillFactor) + 1; }
// Параметризованный конструктор public HashTable(int initialCapacity) { if (initialCapacity < 1) { throw new ArgumentOutOfRangeException("Заданный размер меньше 1"); } _array = new HashTableArray <TKey, TValue>(initialCapacity); // Увеличение максимального значения _maxItemsAtCurrentSize = (int)(initialCapacity * _fillFactor) + 1; }
public void Add(TKey key, TValue value) { if (maxItemsAtCurrentSize == count) { HashTableArray <TKey, TValue> newArray = new HashTableArray <TKey, TValue>(maxItemsAtCurrentSize * 2); foreach (HashTableNodePair <TKey, TValue> item in array) { } } else { } }
public void Add(TKey key, TValue value) { if (_count > -_maxItemsAtCurrentSize) { HashTableArray <TKey, TValue> largerArray = new HashTableArray <TKey, TValue>(_array.Capacity * 2); 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++; }
public void Add(TKey key, TValue value) { if (_count >= _maxItemsAtCurrentSize) { // Увеличение размерности массива HashTableArray <TKey, TValue> largerArray = new HashTableArray <TKey, TValue>(_array.Capacity * 2); // перезапись заначения в массив 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++; }
/// <summary> /// Adds the key/value pair to the hash table. /// If the key already exists in the hash table an ArgumentException will be thrown /// </summary> /// <param name="key">The key of the item being added</param> /// <param name="value">The value of the item being added</param> public void Add(TKey key, TValue value) { //if we are at capacity, the array needs to grow if (_count >= _maxItemsAtCurrentSize) { //allocate the larger array HashTableArray <TKey, TValue> largerArray = new HashTableArray <TKey, TValue>(_array.Capacity * 2); //and re-add each item to the new array foreach (HashTableNodePair <TKey, TValue> node in _array.Items) { largerArray.Add(node.Key, node.Value); } //the larger array is now the hash table storage _array = largerArray; //update the new max items cached value _maxItemsAtCurrentSize = (int)(_array.Capacity * _fillFactor) + 1; } _array.Add(key, value); _count++; }