1 |
#Region "Microsoft.VisualBasic::21183c37f8ca04b784aced47ebe7c7ea, Microsoft.VisualBasic.Core\ApplicationServices\Parallel\Threads\Groups\GroupAPI.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 |
|
41 |
#End Region
|
42 |
|
43 |
Imports System.Runtime.CompilerServices
|
44 |
|
45 |
Namespace Parallel
|
46 |
|
47 |
Public Module GroupAPI
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
<Extension> Public Function ParallelGroup(Of T, T_TAG)(source As IEnumerable(Of T), __getGuid As Func(Of T, T_TAG)) As GroupResult(Of T, T_TAG)()
|
57 |
Call $"Generating guid index...".__DEBUG_ECHO
|
58 |
Dim TAGS = (From x As T In source.AsParallel Select guid = __getGuid(x), x).ToArray
|
59 |
Call Console.WriteLine($"[DEBUG {Now.ToString}] Start to create lquery partitions...")
|
60 |
Dim Partitions = TAGS.Split(TAGS.Length / Environment.ProcessorCount)
|
61 |
Call Console.WriteLine($"[DEBUG {Now.ToString}] Invoke parallel group operations....")
|
62 |
Call Console.WriteLine($"[DEBUG {Now.ToString}] First groups...")
|
63 |
Dim FirstGroups = (From Partition In Partitions.AsParallel
|
64 |
Select (From obj In (From Token In Partition
|
65 |
Select Token.guid
|
66 |
Group guid By guid Into Group).ToArray Select obj.guid).ToArray).ToArray.Unlist
|
67 |
Call Console.WriteLine($"[DEBUG {Now.ToString}] Unique group...")
|
68 |
Dim UniqueGroup = (From TAG As T_TAG
|
69 |
In FirstGroups.AsParallel
|
70 |
Select TAG
|
71 |
Group TAG By TAG Into Group).ToArray
|
72 |
Call Console.WriteLine($"[DEBUG {Now.ToString}] Generating group result....")
|
73 |
Call Console.WriteLine(" * Cache data....")
|
74 |
Dim Cache = (From TAG In UniqueGroup.AsParallel Select TAG, List = New List(Of T)).ToArray
|
75 |
Call Console.WriteLine(" * Address data.....")
|
76 |
Dim Addressing = (From obj In TAGS.AsParallel Select obj, List = (From item In Cache Where item.TAG.TAG.Equals(obj.guid) Select item.List).FirstOrDefault).ToArray
|
77 |
For Each Address In Addressing
|
78 |
Call Address.List.Add(Address.obj.x)
|
79 |
Next
|
80 |
Call Console.WriteLine(" * Generate result.....")
|
81 |
Dim LQuery = (From TAG In Cache.AsParallel Select New GroupResult(Of T, T_TAG)() With {.Tag = TAG.TAG.TAG, .Group = TAG.List.ToArray}).ToArray
|
82 |
Call Console.WriteLine($"[DEBUG {Now.ToString}] Parallel group operation job done!")
|
83 |
Return LQuery
|
84 |
End Function
|
85 |
End Module
|
86 |
End Namespace
|