示例#1
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedSizeQueue{T}" /> class.
 /// </summary>
 public FixedSizeQueue(IEnumerable <T> source)
 {
     _indexDequeue = 0;
     _entries      = new FixedSizeBucket <T>(source);
     Capacity      = _entries.Capacity;
     _indexEnqueue = _entries.Count;
     _preCount     = _indexEnqueue;
 }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="FixedSizeQueue{T}" /> class.
 /// </summary>
 /// <param name="capacity">The capacity.</param>
 public FixedSizeQueue(int capacity)
 {
     Capacity      = NumericHelper.PopulationCount(capacity) == 1 ? capacity : NumericHelper.NextPowerOf2(capacity);
     _preCount     = 0;
     _indexEnqueue = 0;
     _indexDequeue = 0;
     _entries      = new FixedSizeBucket <T>(Capacity);
 }
示例#3
0
 /// <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="needleFactory">The delegate that is invoked to create a needle</param>
 /// <param name="capacity">The capacity.</param>
 /// <exception cref="InvalidOperationException"></exception>
 /// <exception cref="ArgumentNullException"><paramref name="valueFactory"/> is <c>null</c>.</exception>
 public NeedleBucket(Func <T> valueFactory, Func <T, TNeedle> needleFactory, int capacity)
 {
     if (valueFactory == null)
     {
         throw new ArgumentNullException(nameof(valueFactory));
     }
     _needleFactory      = needleFactory ?? throw new ArgumentNullException(nameof(needleFactory));
     _reservoir          = new NeedleReservoir <T, TNeedle>(_needleFactory);
     _needleIndexFactory = index => Reservoir.GetNeedle(new ValueFuncClosure <T>(valueFactory).InvokeReturn());
     _entries            = new FixedSizeBucket <TNeedle>(capacity);
 }
示例#4
0
 /// <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;
 }
示例#5
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="CircularBucket{T}" /> class.
 /// </summary>
 /// <param name="capacity">The capacity.</param>
 public CircularBucket(int capacity)
 {
     Capacity = NumericHelper.PopulationCount(capacity) == 1 ? capacity : NumericHelper.NextPowerOf2(capacity);
     _index   = -1;
     _entries = new FixedSizeBucket <T>(Capacity);
 }