コード例 #1
0
        //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++;
        }
コード例 #2
0
        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++;
        }
コード例 #3
0
        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++;
        }
コード例 #4
0
        /// <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++;
        }