/// <summary> /// Initializes a new instance of the <see cref="FixedSizeBucket{T}" /> class. /// </summary> public FixedSizeBucket(IEnumerable <T> source) { if (source == null) { throw new ArgumentNullException("source"); } var collection = source as ICollection <T>; _entries = ArrayReservoir <object> .GetArray(collection == null? 64 : collection.Count); _capacity = _entries.Length; foreach (var item in source) { if (_count == _capacity) { var old = _entries; _entries = ArrayReservoir <object> .GetArray(_capacity << 1); if (old != null) { Array.Copy(old, 0, _entries, 0, _count); ArrayReservoir <object> .DonateArray(old); } _capacity = _entries.Length; } _entries[_count] = (object)item ?? BucketHelper.Null; _count++; } }
/// <summary> /// Initializes a new instance of the <see cref="FixedSizeBucket{T}" /> class. /// </summary> /// <param name="capacity">The capacity.</param> public FixedSizeBucket(int capacity) { _count = 0; _entries = ArrayReservoir <object> .GetArray(capacity); _capacity = _entries.Length; }
/// <summary> /// Initializes a new instance of the <see cref="FixedSizeBucket{T}" /> class. /// </summary> public FixedSizeBucket(T[] source) { if (source == null) { throw new ArgumentNullException("source"); } _entries = ArrayReservoir <object> .GetArray(source.Length); _capacity = _entries.Length; foreach (var item in source) { _entries[_count] = (object)item ?? BucketHelper.Null; _count++; } }