1 |
#Region "Microsoft.VisualBasic::0c122d047d50bdca55d274a682e7e847, Microsoft.VisualBasic.Core\ComponentModel\DataStructures\Set\SetsExtension.vb"
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
#End Region
|
41 |
|
42 |
Imports System.Runtime.CompilerServices
|
43 |
Imports Microsoft.VisualBasic.CommandLine.Reflection
|
44 |
Imports Microsoft.VisualBasic.ComponentModel.DataStructures
|
45 |
|
46 |
Public Module SetsExtension
|
47 |
|
48 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
49 |
<Extension> Public Function ToArray(Of T)(s As [Set], [ctype] As Func(Of Object, T)) As T()
|
50 |
Return s.ToArray _
|
51 |
.Select([ctype]) _
|
52 |
.ToArray
|
53 |
End Function
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
62 |
<Extension> Public Function ToArray(Of T)(s As [Set]) As T()
|
63 |
Return s.ToArray _
|
64 |
.Select(Function(x) DirectCast(x, T)) _
|
65 |
.ToArray
|
66 |
End Function
|
67 |
|
68 |
#Region "API"
|
69 |
|
70 |
|
71 |
差集,函数会从<paramref name="s1"/>集合之中删除<paramref name="s2"/>中共同的元素
|
72 |
|
73 |
<param name="s1"></param>
|
74 |
<param name="s2"></param>
|
75 |
|
76 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
77 |
<ExportAPI("Except")>
|
78 |
Public Function Except(s1 As [Set], s2 As [Set]) As [Set]
|
79 |
Return s1 - s2
|
80 |
End Function
|
81 |
|
82 |
|
83 |
就并集
|
84 |
|
85 |
<param name="s1"></param>
|
86 |
<param name="s2"></param>
|
87 |
|
88 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
89 |
<ExportAPI("Union", Info:="Performs a union of two sets.")>
|
90 |
Public Function Union(s1 As [Set], s2 As [Set]) As [Set]
|
91 |
Return s1 Or s2
|
92 |
End Function
|
93 |
|
94 |
|
95 |
求交集
|
96 |
|
97 |
<param name="s1"></param>
|
98 |
<param name="s2"></param>
|
99 |
|
100 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
101 |
<ExportAPI("Intersection", Info:="Performs an intersection of two sets.")>
|
102 |
Public Function Intersection(s1 As [Set], s2 As [Set]) As [Set]
|
103 |
Return s1 And s2
|
104 |
End Function
|
105 |
|
106 |
|
107 |
将任意序列转换为集合类型
|
108 |
|
109 |
<param name="source"></param>
|
110 |
|
111 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
112 |
<ExportAPI("As.Set")>
|
113 |
<Extension>
|
114 |
Public Function AsSet(source As IEnumerable) As [Set]
|
115 |
Return New [Set](source)
|
116 |
End Function
|
117 |
|
118 |
<ExportAPI("As.Array")>
|
119 |
Public Function ToArray([set] As [Set]) As Object()
|
120 |
Return [set].ToArray
|
121 |
End Function
|
122 |
|
123 |
|
124 |
Create a string set
|
125 |
|
126 |
<param name="strings"></param>
|
127 |
|
128 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
129 |
<Extension>
|
130 |
Public Function AsSet(strings As IEnumerable(Of String)) As StringSet
|
131 |
Return New StringSet(strings)
|
132 |
End Function
|
133 |
#End Region
|
134 |
End Module
|