1 | #Region "Microsoft.VisualBasic::6865bc93e0c1e1c2ed06c0102388141a, Microsoft.VisualBasic.Core\ComponentModel\DataStructures\BitMap\HashModel.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Interface IAddressOf |
35 | ' |
36 | ' |
37 | ' |
38 | ' Interface IAddress |
39 | ' |
40 | ' Properties: Address |
41 | ' |
42 | ' Sub: Assign |
43 | ' |
44 | ' Interface IHashHandle |
45 | ' |
46 | ' |
47 | ' |
48 | ' Class IHashValue |
49 | ' |
50 | ' Properties: Address, ID, obj |
51 | ' |
52 | ' Sub: Assign |
53 | ' |
54 | ' Module AddressedValueExtensions |
55 | ' |
56 | ' Function: Vector |
57 | ' |
58 | ' |
59 | ' /********************************************************************************/ |
60 | |
61 | #End Region |
62 | |
63 | Imports System.Runtime.CompilerServices |
64 | Imports Microsoft.VisualBasic.ComponentModel.Collection.Generic |
65 | Imports Microsoft.VisualBasic.Language |
66 | |
67 | Namespace ComponentModel |
68 | |
69 | ''' <summary> |
70 | ''' This object gets a object handle value to indicated that the position this object exists |
71 | ''' in the list collection structure. |
72 | ''' (这个对象具有一个用于指明该对象在列表对象中的位置的对象句柄值) |
73 | ''' </summary> |
74 | ''' <remarks></remarks> |
75 | Public Interface IAddressOf : Inherits IAddress(Of Integer) |
76 | End Interface |
77 | |
78 | ''' <summary> |
79 | ''' This object gets a object handle value to indicated that the position this object exists |
80 | ''' in the list collection structure. |
81 | ''' (这个对象具有一个用于指明该对象在列表对象中的位置的对象句柄值) |
82 | ''' </summary> |
83 | ''' <remarks></remarks> |
84 | Public Interface IAddress(Of T As IComparable) |
85 | |
86 | ''' <summary> |
87 | ''' The ID that this object in a list instance. |
88 | ''' (本对象在一个列表对象中的位置索引号) |
89 | ''' </summary> |
90 | ''' <value></value> |
91 | ''' <returns></returns> |
92 | ''' <remarks>因为索引号在赋值之后是不可以被修改了的,所以这个属性使用ReadOnly</remarks> |
93 | ReadOnly Property Address As T |
94 | |
95 | Sub Assign(address As T) |
96 | End Interface |
97 | |
98 | Public Interface IHashHandle : Inherits IAddressOf, INamedValue |
99 | End Interface |
100 | |
101 | Public Class IHashValue(Of T As INamedValue) : Inherits BaseClass |
102 | Implements IHashHandle |
103 | |
104 | Public Property obj As T |
105 | Public Property Address As Integer Implements IAddressOf.Address |
106 | Public Property ID As String Implements INamedValue.Key |
107 | Get |
108 | Return obj.Key |
109 | End Get |
110 | Set(value As String) |
111 | obj.Key = value |
112 | End Set |
113 | End Property |
114 | |
115 | Public Sub Assign(address As Integer) Implements IAddress(Of Integer).Assign |
116 | _Address = address |
117 | End Sub |
118 | End Class |
119 | |
120 | Public Module AddressedValueExtensions |
121 | |
122 | <Extension> |
123 | Public Function Vector(Of T As IAddress(Of Integer), TOut)(source As IEnumerable(Of T), length As Integer, getValue As Func(Of T, TOut)) As TOut() |
124 | Dim chunk As TOut() = New TOut(length - 1) {} |
125 | |
126 | For Each x As T In source |
127 | chunk(x.Address) = getValue(x) |
128 | Next |
129 | |
130 | Return chunk |
131 | End Function |
132 | End Module |
133 | End Namespace |