Example #1
0
        public TValue this[TKey key]
        {
            get
            {
                if (!Contains(key))
                {
                    throw new ArgumentException();
                }

                int position = GetArrayPosition(key);

                return(_items[position].Value);
            }
            set
            {
                if (!Contains(key))
                {
                    throw new ArgumentException();
                }

                int position = GetArrayPosition(key);

                if (value == null)
                {
                    _items[position] = null;
                }
                else
                {
                    _items[position] = new HashTableNode <TKey, TValue>(key, value);
                }
            }
        }
        public HashTableNode Add(string name)
        {
            HashTableNode node = null;
            var           b    = dict.TryGetValue(name, out node);

            if (!b)
            {
                node       = new HashTableNode(name);
                dict[name] = node;
            }
            return(node);

            /*if (!dict.ContainsKey(name))
             * {
             *  var node = new HashTableNode(name);
             *  dict[name] = node;
             *  return node;
             * }
             * return dict[name];*/

            /*if (count / hash_size * 100 > SymbolTableConstants.HashTable_StartResise)
             *  Resize(hash_size + hash_size / 100 * SymbolTableConstants.HashTable_ProcResize);
             * int tn = GetHash(node.Name);
             * if (hash_arr[tn] == null)
             * {
             *  hash_arr[tn] = node;
             *  count++;
             * }
             * return hash_arr[tn];*/
        }
Example #3
0
        private void Resize()
        {
            Size *= 2;
            var temp = new HashTableNode <TKey, TValue> [Size];

            foreach (var el in _items)
            {
                var index = GetArrayPosition(el.Key);
                temp[index] = new HashTableNode <TKey, TValue>(el.Key, el.Value);
            }

            _items = temp;
        }
        public HashTableNode Find(string name)
        {
            HashTableNode node = null;

            dict.TryGetValue(name, out node);
            return(node);

            /*if (dict.ContainsKey(name))
             *  return dict[name];
             * else return null;*/

            /*int h = GetHash(name);
             * //if (hash_arr[h] != null)
             * //    return hash_arr[h];
             * return hash_arr[h];*/
        }
Example #5
0
        private void setOnBucket(int hash, string key, T value)
        {
            if (_data[hash] == null)
            {
                _data[hash] = new HashTableNode <T>(key, value);
            }
            else
            {
                var current = _data[hash];
                while (current.Next != null)
                {
                    current = current.Next;
                }

                current.Next = new HashTableNode <T>(key, value);
            }
        }
        public void Add(object key, object value)
        {
            if (Contains(key))
            {
                throw new DuplicateNameException();
            }

            int index = Hash(key);

            if (GetLoadfactor() >= LOAD_FACTOR)
            {
                Resize();
            }

            _array[index] = new HashTableNode(key, value);
            Size++;
        }
Example #7
0
        public void Add(TKey key, TValue value)
        {
            if (Contains(key))
            {
                throw new ArgumentException();
            }

            int position = GetArrayPosition(key);

            _items[position] = new HashTableNode <TKey, TValue>(key, value);
            _hashLoad++;
            Count++;

            if (IsResizeNeeded)
            {
                Resize();
            }
        }