/// <summary> /// Initializes a new instance of the <see cref="Bag<T>"/> class. /// </summary> /// <param name="capacity">The initial capacity of the bag.</param> /// <param name="comparer">The comparer to use when testing equality.</param> public Bag(int capacity, IEqualityComparer <T> comparer) { if (comparer == null) { throw new ArgumentNullException("comparer"); } data = new VisitableHashtable <T, int>(capacity, comparer); }
/// <summary> /// Compares the current instance with another object of the same type. /// </summary> /// <param name="obj">An object to compare with this instance.</param> /// <returns> /// A 32-bit signed integer that indicates the relative order of the objects being compared. The return value has these meanings: Value Meaning Less than zero This instance is less than obj. Zero This instance is equal to obj. Greater than zero This instance is greater than obj. /// </returns> /// <exception cref="T:System.ArgumentException">obj is not the same type as this instance. </exception> public int CompareTo(object obj) { if (obj == null) { throw new ArgumentNullException("obj"); } if (obj.GetType() == this.GetType()) { VisitableHashtable <TKey, TValue> h = obj as VisitableHashtable <TKey, TValue>; return(this.Count.CompareTo(h.Count)); } else { return(this.GetType().FullName.CompareTo(obj.GetType().FullName)); } }
/// <summary> /// Initializes a new instance of the <see cref="Bag<T>"/> class. /// </summary> /// <param name="dictionary">The dictionary to copy values from.</param> private Bag(IDictionary <T, int> dictionary) { #region Asserts Debug.Assert(dictionary != null); #endregion data = new VisitableHashtable <T, int>(dictionary); // Update the count using (Dictionary <T, int> .Enumerator enumerator = data.GetEnumerator()) { while (enumerator.MoveNext()) { count += enumerator.Current.Value; } } }
/// <summary> /// Initializes a new instance of the <see cref="Bag<T>"/> class. /// </summary> /// <param name="capacity">The initial capacity of the bag.</param> public Bag(int capacity) { data = new VisitableHashtable <T, int>(capacity); }
/// <summary> /// Initializes a new instance of the <see cref="Bag<T>"/> class. /// </summary> public Bag() { data = new VisitableHashtable <T, int>(); }