Exemple #1
0
        //============================================================
        // <T>移除指定名称的内容。</T>
        //
        // @param name 名称
        //============================================================
        public virtual V Remove(N name)
        {
            // 检查名称
            if (null == name)
            {
                throw new NullReferenceException();
            }
            // 查找节点
            int index = -1;
            int hash  = InnerCode(name);
            int pos   = hash % _entries.Length;

            RHash.FEntry prior = _entries[pos];
            RHash.FEntry entry = prior;
            while (null != entry)
            {
                if (entry._hash == hash)
                {
                    if (InnerEquals(name, _names[entry._index]))
                    {
                        index = entry._index;
                        if (entry == prior)
                        {
                            _entries[pos] = entry._next;
                        }
                        else
                        {
                            prior._next = entry._next;
                        }
                        break;
                    }
                }
                prior = entry;
                entry = entry._next;
            }
            // 有移除操作
            if (-1 != index)
            {
                V old = _values[index];
                // 修正哈希入口列表
                RHash.Remove(_entries, index);
                // 修正名称和内容数组
                int move = _count - index - 1;
                if (move > 0)
                {
                    Array.Copy(_names, index + 1, _names, index, move);
                    Array.Copy(_values, index + 1, _values, index, move);
                }
                // 修正最后元素
                _count--;
                _names[_count]  = default(N);
                _values[_count] = default(V);
                return(old);
            }
            return(default(V));
        }