Example #1
0
        /// <summary>
        /// Remove all items in a supplied collection from this bag, counting multiplicities.
        /// </summary>
        /// <param name="items">The items to remove.</param>
        public virtual void RemoveAll(SCG.IEnumerable <T> items)
        {
#warning Improve if items is a counting bag
            updatecheck();
            bool mustRaise = (ActiveEvents & (EventTypeEnum.Changed | EventTypeEnum.Removed)) != 0;
            RaiseForRemoveAllHandler raiseHandler = mustRaise ? new RaiseForRemoveAllHandler(this) : null;
            foreach (T item in items)
            {
                KeyValuePair <T, int> p = new KeyValuePair <T, int>(item, 0);
                if (dict.Find(ref p))
                {
                    size--;
                    if (p.Value == 1)
                    {
                        dict.Remove(p);
                    }
                    else
                    {
                        p.Value--;
                        dict.Update(p);
                    }
                    if (mustRaise)
                    {
                        raiseHandler.Remove(p.Key);
                    }
                }
            }
            if (mustRaise)
            {
                raiseHandler.Raise();
            }
        }
Example #2
0
        public virtual void RemoveAll <U>(SCG.IEnumerable <U> items) where U : T
        {
#warning Improve if items is a counting bag
            updatecheck();
            bool mustRaise = (ActiveEvents & (EventTypeEnum.Changed | EventTypeEnum.Removed)) != 0;
            RaiseForRemoveAllHandler raiseHandler = mustRaise ? new RaiseForRemoveAllHandler(this) : null;
            foreach (U item in items)
            {
                Multiplicity <T> p = new Multiplicity <T>(item, 0);
                if (dict.Find(ref p))
                {
                    Size--;
                    if (p.Count == 1)
                    {
                        dict.Remove(p);
                    }
                    else
                    {
                        p.Count--;
                        dict.Update(p);
                    }
                    if (mustRaise)
                    {
                        raiseHandler.Remove(p.Value);
                    }
                }
            }
            if (mustRaise)
            {
                raiseHandler.Raise();
            }
        }
Example #3
0
        /// <summary>
        /// Remove all items not in some other collection from this one. 
        /// </summary>
        /// <param name="items">The items to retain.</param>
        public void RetainAll(SCG.IEnumerable<T> items)
        {
            //This is O(m*logn) with n bits extra storage
            //(Not better to collect the m items and sort them)
            updatecheck();

            RaiseForRemoveAllHandler raiseHandler = new RaiseForRemoveAllHandler(this);
            bool mustFire = raiseHandler.MustFire;

            int[] toretain = new int[(size >> 5) + 1];
            int ind, j = 0;

            foreach (T item in items)
                if (BinarySearch(item, out ind))
                    toretain[ind >> 5] |= 1 << (ind & 31);

            for (int i = 0; i < size; i++)
                if ((toretain[i >> 5] & (1 << (i & 31))) != 0)
                    array[j++] = array[i];
                else if (mustFire)
                    raiseHandler.Remove(array[i]);

            Array.Clear(array, j, size - j);
            size = j;
            if (mustFire)
                raiseHandler.Raise();
        }
Example #4
0
        /// <summary>
        /// Remove all items in a supplied collection from this set.
        /// </summary>
        /// <param name="items">The items to remove.</param>
        public virtual void RemoveAll(SCG.IEnumerable <T> items)
        {
            updatecheck();
            RaiseForRemoveAllHandler raiseHandler = new RaiseForRemoveAllHandler(this);
            bool raise = raiseHandler.MustFire;
            T    jtem;

            foreach (var item in items)
            {
                jtem = item; if (remove(ref jtem) && raise)
                {
                    raiseHandler.Remove(jtem);
                }
            }

            if (raise)
            {
                raiseHandler.Raise();
            }
        }
Example #5
0
    public virtual void RemoveAll<U>(SCG.IEnumerable<U> items) where U : T
    {
      updatecheck();
      RaiseForRemoveAllHandler raiseHandler = new RaiseForRemoveAllHandler(this);
      bool raise = raiseHandler.MustFire;
      T jtem;
      foreach (U item in items)
      { jtem = item; if (remove(ref jtem) && raise) raiseHandler.Remove(jtem); }
#if SHRINK
			if (size < resizethreshhold / 2 && resizethreshhold > 16)
			{
				int newlength = table.Length;

				while (newlength >= 32 && newlength * fillfactor / 2 > size)
					newlength /= 2;

				resize(newlength - 1);
			}
#endif
      if (raise) raiseHandler.Raise();
    }
Example #6
0
 public virtual void RemoveAll <U>(SCG.IEnumerable <U> items) where U : T
 {
     RaiseForRemoveAllHandler raiseHandler = new RaiseForRemoveAllHandler();
 }