Beispiel #1
0
        /// <summary>
        /// Adds key value pair to the hash table
        /// </summary>
        /// <param name="key">The key to be added</param>
        /// <param name="value">The value to be added</param>
        public void Add(TKey key, TValue value)
        {
            // Are we at capacity?  Do we need to grow the array?
            if (_count >= _maxItemsAtCurrentSize)
            {
                GrowArray();
            }

            // Do the add
            _array.Add(key, value);
            _count++;
        }
Beispiel #2
0
        public void Add(TKey key, TValue value)
        {
            if (_count >= _maxItemsAtCurrSize)
            {
                HashTableArray <TKey, TValue> largerArr = new HashTableArray <TKey, TValue>(_array.Capacity * 2);

                foreach (var node in _array.Items)
                {
                    largerArr.Add(node.Key, node.Value);
                }
                _array = largerArr;

                _maxItemsAtCurrSize = (int)(_array.Capacity * _fillFac) + 1;
            }
            _array.Add(key, value);
            _count++;
        }
Beispiel #3
0
        /// <summary>
        /// Grows the array by twice the current size
        /// </summary>
        private void GrowArray()
        {
            //Create an array twice a large
            HashTableArray <TKey, TValue> largerArray = new HashTableArray <TKey, TValue>(_array.Capacity * 2);

            // Add each existing item to the new array
            foreach (var node in _array.Items)
            {
                largerArray.Add(node.Key, node.Value);
            }

            // Make the larger array the new hash table storage array
            _array = largerArray;

            // Calculate new max items value
            _maxItemsAtCurrentSize = (int)(_array.Capacity * _fillFactor) + 1;
        }