Example #1
0
        /// <summary>
        /// Removes multiple items at once.
        /// </summary>
        public void RemoveMany(RemoveManyDictionaryDelegate <TKey, TValue> checkDelegate)
        {
            if (checkDelegate == null)
            {
                throw new ArgumentNullException("checkDelegate");
            }

            int count = _indexes.Length;

            for (int i = 0; i < count; i++)
            {
                int lastNodeIndex = -1;

                int nodeIndex = _indexes[i];
                while (nodeIndex != -1)
                {
                    TKey   key   = _nodes[nodeIndex]._key;
                    TValue value = _nodes[nodeIndex]._value;

                    if (!checkDelegate(key, value))
                    {
                        lastNodeIndex = nodeIndex;
                        nodeIndex     = _nodes[nodeIndex]._nextNodeIndex;
                        continue;
                    }

                    int nextNodeIndex = _nodes[nodeIndex]._nextNodeIndex;
                    if (lastNodeIndex == -1)
                    {
                        _indexes[i] = nextNodeIndex;
                    }
                    else
                    {
                        _nodes[lastNodeIndex]._nextNodeIndex = nextNodeIndex;
                    }

                    if (!typeof(TKey).IsPrimitive)
                    {
                        _nodes[nodeIndex]._key = default(TKey);
                    }

                    if (!typeof(TValue).IsPrimitive)
                    {
                        _nodes[nodeIndex]._value = default(TValue);
                    }

                    _nodes[nodeIndex]._nextNodeIndex = _indexOfFirstFree;
                    _indexOfFirstFree = nodeIndex;

                    _count--;
                    nodeIndex = nextNodeIndex;
                }
            }
        }
Example #2
0
        /// <summary>
        /// Remove many pairs at once. Each pair will call the checkDelegate to know if it
        /// should be removed or not. This is much faster than iterating the entire
        /// dictionary and then removing the unnecessary items.
        /// </summary>
        public void RemoveMany(RemoveManyDictionaryDelegate <TKey, TValue> checkDelegate)
        {
            if (checkDelegate == null)
            {
                throw new ArgumentNullException("checkDelegate");
            }

            var owner = _GetOwner();

            owner._RemoveMany(checkDelegate);
        }