internal static TNeedle GetNeedle(T value) { TNeedle result; if (_pool.TryGet(out result)) { result.Value = value; } else { result = NeedleHelper.CreateNeedle <T, TNeedle>(value); } return(result); }
/// <summary> /// Initializes a new instance of the <see cref="NeedleBucket{T, TNeedle}" /> class. /// </summary> /// <param name = "valueFactory">The delegate that is invoked to do the lazy initialization of the items.</param> /// <param name="capacity">The capacity.</param> public NeedleBucket(Func<T> valueFactory, int capacity) { if (valueFactory == null) { throw new ArgumentNullException("valueFactory"); } if (!NeedleHelper.CanCreateNeedle<T, TNeedle>()) { throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "Unable to find a way to create {0}", typeof(TNeedle).Name)); } _needleFactory = index => NeedleReservoir<T, TNeedle>.GetNeedle(valueFactory()); _entries = new FixedSizeBucket<TNeedle>(capacity); _comparer = EqualityComparer<T>.Default; }
public void Add(T item) { var needle = NeedleHelper.CreateNeedle <T, TNeedle>(item); _wrapped.Add(needle); }
public void Add(T item) { var needle = NeedleHelper.CreateNeedle <T, TNeedle>(item); _wrapped.Set(Interlocked.Increment(ref _maxIndex), needle); }