| 1 |
#Region "Microsoft.VisualBasic::ad3f839f9168701625cdb64b9795197f, Microsoft.VisualBasic.Core\ComponentModel\Algorithm\BinaryTree\Enumerable.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 ComponentModel.Algorithm.BinaryTree
|
| 46 |
|
| 47 |
Public Module Enumerable
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
```
|
| 53 |
left -> me -> right
|
| 54 |
```
|
| 55 |
</summary>
|
| 56 |
<typeparam name="K"></typeparam>
|
| 57 |
<typeparam name="V"></typeparam>
|
| 58 |
<param name="tree"></param>
|
| 59 |
<returns></returns>
|
| 60 |
<remarks>
|
| 61 |
这个函数是直接将键名和对应的值取出来,如果是需要取出聚类的簇成员,
|
| 62 |
应该使用<see cref="PopulateNodes(Of K, V)"/>方法
|
| 63 |
</remarks>
|
| 64 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 65 |
<Extension>
|
| 66 |
Public Function PopulateSequence(Of K, V)(tree As BinaryTree(Of K, V)) As IEnumerable(Of Map(Of K, V))
|
| 67 |
Return tree.PopulateNodes.Select(Function(n) New Map(Of K, V)(n.Key, n.Value))
|
| 68 |
End Function
|
| 69 |
|
| 70 |
|
| 71 |
将一个给定的二叉树对象转换为一个数组序列
|
| 72 |
</summary>
|
| 73 |
<typeparam name="K"></typeparam>
|
| 74 |
<typeparam name="V"></typeparam>
|
| 75 |
<param name="tree"></param>
|
| 76 |
<returns></returns>
|
| 77 |
<Extension>
|
| 78 |
Public Iterator Function PopulateNodes(Of K, V)(tree As BinaryTree(Of K, V)) As IEnumerable(Of BinaryTree(Of K, V))
|
| 79 |
If Not tree.Left Is Nothing Then
|
| 80 |
For Each node In tree.Left.PopulateNodes
|
| 81 |
Yield node
|
| 82 |
Next
|
| 83 |
End If
|
| 84 |
|
| 85 |
Yield tree
|
| 86 |
|
| 87 |
If Not tree.Right Is Nothing Then
|
| 88 |
For Each node In tree.Right.PopulateNodes
|
| 89 |
Yield node
|
| 90 |
Next
|
| 91 |
End If
|
| 92 |
End Function
|
| 93 |
|
| 94 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 95 |
<Extension>
|
| 96 |
Public Function Values(Of K, V)(tree As BinaryTree(Of K, V)) As IEnumerable(Of V)
|
| 97 |
Return tree.PopulateNodes.Values
|
| 98 |
End Function
|
| 99 |
|
| 100 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 101 |
<Extension>
|
| 102 |
Public Function Values(Of K, V)(nodes As IEnumerable(Of BinaryTree(Of K, V))) As IEnumerable(Of V)
|
| 103 |
Return nodes.Select(Function(n) n.Value)
|
| 104 |
End Function
|
| 105 |
|
| 106 |
<MethodImpl(MethodImplOptions.AggressiveInlining)>
|
| 107 |
<Extension>
|
| 108 |
Public Function ClusterMembers(Of K, V)(node As BinaryTree(Of K, V)) As V()
|
| 109 |
If node Is Nothing Then
|
| 110 |
Return {}
|
| 111 |
Else
|
| 112 |
Return DirectCast(node!values, List(Of V)).ToArray
|
| 113 |
End If
|
| 114 |
End Function
|
| 115 |
End Module
|
| 116 |
End Namespace
|