1 #Region "Microsoft.VisualBasic::6a405701adae07c86e813a7226119ba7, Microsoft.VisualBasic.Core\ComponentModel\Algorithm\BinaryTree\TreeBase.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     '     Class TreeBase
35     
36     '         Properties: root
37     
38     '         Constructor: (+1 OverloadsSub New
39     '         FunctionGetAllNodes
40     
41     
42     ' /********************************************************************************/
43
44 #End Region
45
46 Imports System.Runtime.CompilerServices
47
48 Namespace ComponentModel.Algorithm.BinaryTree
49
50     Public MustInherit Class TreeBase(Of K, V)
51
52         ''' <summary>
53         ''' The root node of this binary tree
54         ''' </summary>
55         ''' <returns></returns>
56         Public ReadOnly Property root As BinaryTree(Of K, V)
57             <MethodImpl(MethodImplOptions.AggressiveInlining)>
58             Get
59                 Return _root
60             End Get
61         End Property
62
63         Protected _root As BinaryTree(Of K, V)
64
65         Protected ReadOnly compares As Comparison(Of K)
66         Protected ReadOnly views As Func(Of K, String)
67         Protected ReadOnly stack As New List(Of BinaryTree(Of K, V))
68
69         ''' <summary>
70         ''' Create an instance of the AVL binary tree.
71         ''' </summary>
72         ''' <param name="compares">Compare between two keys.</param>
73         ''' <param name="views">Display the key as string</param>
74         Sub New(compares As Comparison(Of K), Optional views As Func(Of K, String) = Nothing)
75             Me.compares = compares
76             Me.views = views
77         End Sub
78
79         Public Function GetAllNodes() As BinaryTree(Of K, V)()
80             Return stack.ToArray
81         End Function
82     End Class
83 End Namespace