/// <summary> /// Creates a new ExaArray1D from an enumerable sequence of items. The number of items in the sequence is __unknown__. /// </summary> /// <remarks> /// This factory method is slow because the number of items in the sequence is unknown. When you know the /// number of items, you should use another factory method, where the number of items can be provided. /// /// Performance: O(n) /// </remarks> /// <param name="sequence">The sequence to consume in order to create the array.</param> /// <param name="strategy">The optional optimization strategy.</param> /// <returns>The desired instance</returns> public static ExaArray1D <T> CreateFrom(IEnumerable <T> sequence, Strategy strategy = Strategy.MAX_PERFORMANCE) { var inst = new ExaArray1D <T>(strategy); ulong position = 0; foreach (var element in sequence) { inst.Extend(); inst[position++] = element; } return(inst); }
/// <summary> /// Creates a new ExaArray1D from a collection of items. /// </summary> /// <remarks> /// Performance: O(n) /// </remarks> /// <param name="collection">The collection to use</param> /// <param name="strategy">The optional optimization strategy.</param> /// <returns>The desired instance</returns> public static ExaArray1D <T> CreateFrom(ICollection <T> collection, Strategy strategy = Strategy.MAX_PERFORMANCE) { var inst = new ExaArray1D <T>(strategy); inst.Extend((ulong)collection.Count); ulong position = 0; foreach (var element in collection) { inst[position++] = element; } return(inst); }