|
| 1 | +namespace FSharp.Collections.Immutable |
| 2 | + |
| 3 | +open System |
| 4 | +open System.Collections.Frozen |
| 5 | +open System.Collections.Generic |
| 6 | + |
| 7 | +/// <summary> |
| 8 | +/// Creates frozen sets that compare their elements with an equality comparer (ADR 0001, D12). |
| 9 | +/// </summary> |
| 10 | +/// <remarks> |
| 11 | +/// <para> |
| 12 | +/// <see cref="M:FSharp.Collections.Immutable.FrozenSet.ForComparer``1(System.Collections.Generic.IEqualityComparer{``0})"/> |
| 13 | +/// creates the struct. Its members are the creation functions of <see cref="T:FSharp.Collections.Immutable.FrozenSet"/> |
| 14 | +/// under the same names, with the comparer applied, so that a call reads as one phrase. A frozen set has no builder, so |
| 15 | +/// the struct has no <c>builder</c> member. |
| 16 | +/// </para> |
| 17 | +/// <para> |
| 18 | +/// The struct holds only the comparer, so creating it allocates nothing. Its default value, which no constructor |
| 19 | +/// creates, compares with <see cref="P:System.Collections.Generic.EqualityComparer`1.Default"/>. |
| 20 | +/// </para> |
| 21 | +/// </remarks> |
| 22 | +/// <example id="customComparerFrozenSet-1"> |
| 23 | +/// <code lang="fsharp"> |
| 24 | +/// let names = (FrozenSet.forComparer StringComparer.OrdinalIgnoreCase).ofList [ "Ann"; "ANN"; "Bob" ] |
| 25 | +/// </code> |
| 26 | +/// Evaluates to a frozen set of "Ann" and "Bob" that compares without case. |
| 27 | +/// </example> |
| 28 | +[<Struct; NoComparison; NoEquality>] |
| 29 | +type CustomComparerFrozenSet<'T> = |
| 30 | + |
| 31 | + // A signature reveals the fields of a struct, private ones included (FS0314); null only in the default value |
| 32 | + val private comparer : IEqualityComparer<'T> | null |
| 33 | + |
| 34 | + /// <summary>Creates the struct for an equality comparer.</summary> |
| 35 | + /// <param name="comparer">The equality comparer of the elements of the frozen sets that the struct creates.</param> |
| 36 | + /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="comparer"/> is <see langword="null"/>.</exception> |
| 37 | + new : comparer : IEqualityComparer<'T> -> CustomComparerFrozenSet<'T> |
| 38 | + |
| 39 | + // ---- Creation ---- |
| 40 | + |
| 41 | + /// <summary> |
| 42 | + /// The empty frozen set that compares with the comparer. |
| 43 | + /// </summary> |
| 44 | + /// <remarks> |
| 45 | + /// O(1). The member wraps |
| 46 | + /// <see cref="M:System.Collections.Frozen.FrozenSet.Create``1(System.Collections.Generic.IEqualityComparer{``0},System.ReadOnlySpan{``0})"/>, |
| 47 | + /// which returns <see cref="P:System.Collections.Frozen.FrozenSet`1.Empty"/> for |
| 48 | + /// <see cref="P:System.Collections.Generic.EqualityComparer`1.Default"/>. |
| 49 | + /// </remarks> |
| 50 | + [<CompiledName "Empty">] |
| 51 | + member empty : FrozenSet<'T> |
| 52 | + |
| 53 | + /// <summary> |
| 54 | + /// Creates a frozen set from the elements of an array, compared with the comparer. |
| 55 | + /// </summary> |
| 56 | + /// <param name="array">The input array.</param> |
| 57 | + /// <returns> |
| 58 | + /// The frozen set of the elements that are distinct in the comparer; of the elements that the comparer considers equal, |
| 59 | + /// it holds the first one. |
| 60 | + /// </returns> |
| 61 | + /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="array"/> is <see langword="null"/>.</exception> |
| 62 | + /// <remarks> |
| 63 | + /// O(n). Later changes to the array do not change the frozen set. The member wraps |
| 64 | + /// <see cref="M:System.Collections.Frozen.FrozenSet.ToFrozenSet``1(System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IEqualityComparer{``0})"/>. |
| 65 | + /// </remarks> |
| 66 | + [<CompiledName "OfArray">] |
| 67 | + member ofArray : array : 'T array -> FrozenSet<'T> |
| 68 | + |
| 69 | + /// <summary> |
| 70 | + /// Creates a frozen set from the elements of a list, compared with the comparer. |
| 71 | + /// </summary> |
| 72 | + /// <param name="elements">The input list.</param> |
| 73 | + /// <returns> |
| 74 | + /// The frozen set of the elements that are distinct in the comparer; of the elements that the comparer considers equal, |
| 75 | + /// it holds the first one. |
| 76 | + /// </returns> |
| 77 | + /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="elements"/> is <see langword="null"/>.</exception> |
| 78 | + /// <remarks> |
| 79 | + /// O(n). |
| 80 | + /// </remarks> |
| 81 | + [<CompiledName "OfList">] |
| 82 | + member ofList : elements : 'T list -> FrozenSet<'T> |
| 83 | + |
| 84 | + /// <summary> |
| 85 | + /// Creates a frozen set from the elements of a read-only span, compared with the comparer. |
| 86 | + /// </summary> |
| 87 | + /// <param name="span">The input span.</param> |
| 88 | + /// <returns> |
| 89 | + /// The frozen set of the elements that are distinct in the comparer; of the elements that the comparer considers equal, |
| 90 | + /// it holds the first one. An empty span gives an empty frozen set. |
| 91 | + /// </returns> |
| 92 | + /// <remarks> |
| 93 | + /// O(n). Later changes to the memory under the span do not change the frozen set. The member wraps |
| 94 | + /// <see cref="M:System.Collections.Frozen.FrozenSet.Create``1(System.Collections.Generic.IEqualityComparer{``0},System.ReadOnlySpan{``0})"/>. |
| 95 | + /// </remarks> |
| 96 | + [<CompiledName "OfReadOnlySpan">] |
| 97 | + member ofReadOnlySpan : span : ReadOnlySpan<'T> -> FrozenSet<'T> |
| 98 | + |
| 99 | + /// <summary> |
| 100 | + /// Creates a frozen set from the elements of a sequence, compared with the comparer. |
| 101 | + /// </summary> |
| 102 | + /// <param name="elements">The input sequence, which can be a frozen set with another comparer.</param> |
| 103 | + /// <returns> |
| 104 | + /// The frozen set of the elements that are distinct in the comparer; of the elements that the comparer considers equal, |
| 105 | + /// it holds the first one. |
| 106 | + /// </returns> |
| 107 | + /// <exception cref="T:System.ArgumentNullException">Thrown when <paramref name="elements"/> is <see langword="null"/> or a default flat list.</exception> |
| 108 | + /// <remarks> |
| 109 | + /// <para> |
| 110 | + /// O(n). The member wraps |
| 111 | + /// <see cref="M:System.Collections.Frozen.FrozenSet.ToFrozenSet``1(System.Collections.Generic.IEnumerable{``0},System.Collections.Generic.IEqualityComparer{``0})"/>. |
| 112 | + /// </para> |
| 113 | + /// <para> |
| 114 | + /// A frozen set gets the comparer: the member returns the frozen set itself in O(1) when its comparer equals the |
| 115 | + /// comparer, and otherwise a new frozen set of its elements in the comparer. |
| 116 | + /// </para> |
| 117 | + /// </remarks> |
| 118 | + [<CompiledName "OfSeq">] |
| 119 | + member ofSeq : elements : seq<'T> -> FrozenSet<'T> |
| 120 | + |
| 121 | + /// <summary> |
| 122 | + /// Creates a frozen set from the elements of a span, compared with the comparer. |
| 123 | + /// </summary> |
| 124 | + /// <param name="span">The input span.</param> |
| 125 | + /// <returns> |
| 126 | + /// The frozen set of the elements that are distinct in the comparer; of the elements that the comparer considers equal, |
| 127 | + /// it holds the first one. An empty span gives an empty frozen set. |
| 128 | + /// </returns> |
| 129 | + /// <remarks> |
| 130 | + /// O(n). Later changes to the memory under the span do not change the frozen set. The member converts the span to a |
| 131 | + /// read-only span and wraps |
| 132 | + /// <see cref="M:System.Collections.Frozen.FrozenSet.Create``1(System.Collections.Generic.IEqualityComparer{``0},System.ReadOnlySpan{``0})"/>. |
| 133 | + /// </remarks> |
| 134 | + [<CompiledName "OfSpan">] |
| 135 | + member ofSpan : span : Span<'T> -> FrozenSet<'T> |
| 136 | + |
| 137 | + /// <summary> |
| 138 | + /// Creates a frozen set of one element that compares with the comparer. |
| 139 | + /// </summary> |
| 140 | + /// <param name="value">The element.</param> |
| 141 | + /// <returns>The frozen set of one element.</returns> |
| 142 | + /// <remarks> |
| 143 | + /// O(1). |
| 144 | + /// </remarks> |
| 145 | + [<CompiledName "Singleton">] |
| 146 | + member singleton : value : 'T -> FrozenSet<'T> |
| 147 | + |
| 148 | + // ---- Properties ---- |
| 149 | + |
| 150 | + /// <summary> |
| 151 | + /// The equality comparer of the elements of the frozen sets that the struct creates. |
| 152 | + /// </summary> |
| 153 | + /// <remarks> |
| 154 | + /// O(1). The default value of the struct returns <see cref="P:System.Collections.Generic.EqualityComparer`1.Default"/>. |
| 155 | + /// </remarks> |
| 156 | + member Comparer : IEqualityComparer<'T> |
0 commit comments