Exemplo n.º 1
0
        /// <summary>
        /// Retrieve or creates a new needle at the specified index.
        /// </summary>
        /// <param name="index">The index.</param>
        /// <returns>The needle.</returns>
        /// <exception cref="ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception>
        public TNeedle GetNeedle(int index)
        {
            var newNeedle = _needleIndexFactory(index);

            if (_entries.Insert(index, newNeedle, out var found))
            {
                return(newNeedle);
            }
            // we just failed to insert, meaning that we created a useless needle
            // donate it
            Reservoir.DonateNeedle(newNeedle);
            return(found);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Retrieve or creates a new needle at the specified index.
 /// </summary>
 /// <param name="index">The index.</param>
 /// <returns>The needle.</returns>
 /// <exception cref="System.ArgumentOutOfRangeException">index;index must be greater or equal to 0 and less than capacity</exception>
 public TNeedle GetNeedle(int index)
 {
     TNeedle found;
     var newNeedle = _needleFactory(index);
     if (_entries.Insert(index, newNeedle, out found))
     {
         return newNeedle;
     }
     // we just failed to insert, meaning that we created a usless needle
     // donate it
     NeedleReservoir<T, TNeedle>.DonateNeedle(newNeedle);
     return found;
 }