/// <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> /// Initializes a new instance of the <see cref="Bag<T>" /> class. /// </summary> /// <param name="dictionary"> The dictionary to copy values from. </param> Bag(IDictionary <T, int> dictionary) { #region Asserts Debug.Assert(dictionary != null); #endregion _data = new VisitableHashtable <T, int>(dictionary); // Update the count using (var 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>(); }