示例#1
0
 /// <summary>
 /// Determines if this bag is a proper subset of another bag. Neither bag is modified.
 /// This bag is a subset of <paramref name="otherBag"/> if every element in this bag
 /// is also in <paramref name="otherBag"/>, at least the same number of
 /// times. Additional, this bag must have strictly fewer items than <paramref name="otherBag"/>.
 /// </summary>
 /// <remarks>IsProperSubsetOf is computed in time O(N), where N is the number of unique items in this bag.</remarks>
 /// <param name="otherBag">Bag to compare to.</param>
 /// <returns>True if this is a proper subset of <paramref name="otherBag"/>.</returns>
 /// <exception cref="InvalidOperationException">This bag and <paramref name="otherBag"/> don't use the same method for comparing items.</exception>
 public bool IsProperSubsetOf(Bag <T> otherBag)
 {
     return(otherBag.IsProperSupersetOf(this));
 }
示例#2
0
        /// <summary>
        /// Makes a shallow clone of this bag; i.e., if items of the
        /// bag are reference types, then they are not cloned. If T is a value type,
        /// then each element is copied as if by simple assignment.
        /// </summary>
        /// <remarks>Cloning the bag takes time O(N), where N is the number of unquie items in the bag.</remarks>
        /// <returns>The cloned bag.</returns>
        public Bag <T> Clone()
        {
            Bag <T> newBag = new Bag <T>(equalityComparer, keyEqualityComparer, hash.Clone(null), count);

            return(newBag);
        }