/// <summary>
        /// Constructs a new builder.
        /// </summary>
        /// <param name="initialize">Pass <c>true</c>.</param>
        public SparseArrayBuilder(bool initialize)
            : this()
        {
            // Once C# gains parameterless struct constructors, please
            // remove this workaround.
            Debug.Assert(initialize);

            _builder = new LargeArrayBuilder <T>(initialize: true);
        }
        /// <summary>Converts an enumerable to an array.</summary>
        /// <param name="source">The enumerable to convert.</param>
        /// <returns>The resulting array.</returns>
        internal static T[] ToArray <T>(IEnumerable <T> source)
        {
            Debug.Assert(source != null);

            if (source is ICollection <T> collection)
            {
                int count = collection.Count;
                if (count == 0)
                {
                    return(Array.Empty <T>());
                }

                var result = new T[count];
                collection.CopyTo(result, arrayIndex: 0);
                return(result);
            }

            var builder = new LargeArrayBuilder <T>(initialize: true);

            builder.AddRange(source);
            return(builder.ToArray());
        }
 /// <summary>
 /// Constructs a new builder.
 /// </summary>
 public SparseArrayBuilder()
 {
     this     = default;
     _builder = new LargeArrayBuilder <T>();
 }