| | | 1 | | namespace DirectSight.Parser.Analysis.LineCoverage; |
| | | 2 | | |
| | | 3 | | /// <summary> |
| | | 4 | | /// Factory for creating instances of <see cref="ILineInfo{T}"/>. The factory decides which implementation to use based |
| | | 5 | | /// </summary> |
| | | 6 | | internal static class LineInfoFactory |
| | | 7 | | { |
| | | 8 | | /// <summary> |
| | | 9 | | /// Creates a new instance of an <see cref="ILineInfo{T}"/> implementation with the specified length and default val |
| | | 10 | | /// </summary> |
| | | 11 | | /// <remarks>For smaller lengths, an array-based implementation is used for faster enumeration. |
| | | 12 | | /// For larger or sparse data sets, a dictionary-based implementation is used for improved memory |
| | | 13 | | /// efficiency.</remarks> |
| | | 14 | | /// <typeparam name="T">The type of the values stored in the line information.</typeparam> |
| | | 15 | | /// <param name="length">The total number of elements in the line information. Must be non-negative.</param> |
| | | 16 | | /// <param name="defaultValue">The value to assign to all elements initially.</param> |
| | | 17 | | /// <returns>An <see cref="ILineInfo{T}"/> instance containing the specified number of elements, each initialized to |
| | | 18 | | /// value.</returns> |
| | | 19 | | public static ILineInfo<T> Create<T>(long length, T defaultValue) |
| | 7058 | 20 | | { |
| | | 21 | | // Array-based implementation is faster when enumerating the results. The dictionary-based implementation is mor |
| | 7058 | 22 | | if (length < 2000) |
| | 7058 | 23 | | { |
| | 7058 | 24 | | return new ArrayBasedLineInfo<T>(length, defaultValue); |
| | | 25 | | } |
| | | 26 | | else |
| | 0 | 27 | | { |
| | 0 | 28 | | return new DictionaryBasedLineInfo<T>(length, defaultValue); |
| | | 29 | | } |
| | 7058 | 30 | | } |
| | | 31 | | } |