| 1 | #Region "Microsoft.VisualBasic::4fbab0daea0400bdc4523d2bcc428230, Microsoft.VisualBasic.Core\ComponentModel\Algorithm\base\SlideWindow\SlideWindow.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 | ' Structure SlideWindow |
| 35 | ' |
| 36 | ' Properties: Index, Items, Left, Length, Right |
| 37 | ' |
| 38 | ' Function: GetEnumerator, GetEnumerator1, ToString |
| 39 | ' |
| 40 | ' Sub: Assign |
| 41 | ' |
| 42 | ' |
| 43 | ' /********************************************************************************/ |
| 44 | |
| 45 | #End Region |
| 46 | |
| 47 | Imports System.Runtime.CompilerServices |
| 48 | Imports Microsoft.VisualBasic.ComponentModel.Ranges.Model |
| 49 | Imports Microsoft.VisualBasic.Language |
| 50 | Imports Microsoft.VisualBasic.Serialization.JSON |
| 51 | |
| 52 | Namespace ComponentModel.Algorithm.base |
| 53 | |
| 54 | ''' <summary> |
| 55 | ''' A slide window data model.(滑窗操作的数据模型) |
| 56 | ''' </summary> |
| 57 | ''' <typeparam name="T"></typeparam> |
| 58 | ''' <remarks></remarks> |
| 59 | Public Structure SlideWindow(Of T) |
| 60 | Implements IEnumerable(Of T), IAddressOf |
| 61 | Implements IGrouping(Of Integer, T) |
| 62 | Implements Value(Of T()).IValueOf |
| 63 | Implements IRange(Of Integer) |
| 64 | |
| 65 | ''' <summary> |
| 66 | ''' The position of the current Windows in the Windows list.(在创建的滑窗的队列之中当前的窗口对象的位置) |
| 67 | ''' </summary> |
| 68 | ''' <value></value> |
| 69 | ''' <returns></returns> |
| 70 | ''' <remarks></remarks> |
| 71 | Public Property Index As Integer Implements IAddressOf.Address, IGrouping(Of Integer, T).Key |
| 72 | ''' <summary> |
| 73 | ''' The elements in this slide window.(这个划窗之中的元素的列表) |
| 74 | ''' </summary> |
| 75 | ''' <returns></returns> |
| 76 | Public Property Items As T() Implements Value(Of T()).IValueOf.Value |
| 77 | |
| 78 | #Region "Index Range" |
| 79 | |
| 80 | Default Public ReadOnly Property Item(index As Integer) As T |
| 81 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 82 | Get |
| 83 | If index < 0 Then |
| 84 | Return _Items(Length + index) |
| 85 | Else |
| 86 | Return _Items(index) |
| 87 | End If |
| 88 | End Get |
| 89 | End Property |
| 90 | |
| 91 | ''' <summary> |
| 92 | ''' The left start position of the current slide Windows segment on the original sequence. |
| 93 | ''' (当前窗口在原始的序列之中的左端起始位点) |
| 94 | ''' </summary> |
| 95 | ''' <value></value> |
| 96 | ''' <returns></returns> |
| 97 | ''' <remarks></remarks> |
| 98 | Public Property Left As Integer Implements IRange(Of Integer).Min |
| 99 | |
| 100 | Public ReadOnly Property Right As Integer Implements IRange(Of Integer).Max |
| 101 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 102 | Get |
| 103 | Return Left + Length |
| 104 | End Get |
| 105 | End Property |
| 106 | |
| 107 | #End Region |
| 108 | |
| 109 | ''' <summary> |
| 110 | ''' The length of the slide window.(窗口长度) |
| 111 | ''' </summary> |
| 112 | ''' <value></value> |
| 113 | ''' <returns></returns> |
| 114 | ''' <remarks></remarks> |
| 115 | Public ReadOnly Property Length As Integer |
| 116 | Get |
| 117 | If Items.IsNullOrEmpty Then |
| 118 | Return 0 |
| 119 | Else |
| 120 | Return Items.Length |
| 121 | End If |
| 122 | End Get |
| 123 | End Property |
| 124 | |
| 125 | Public Sub Assign(address As Integer) Implements IAddress(Of Integer).Assign |
| 126 | Index = address |
| 127 | End Sub |
| 128 | |
| 129 | Public Overrides Function ToString() As String |
| 130 | Return $"{Index} --> {Items.GetJson}" |
| 131 | End Function |
| 132 | |
| 133 | Public Iterator Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator |
| 134 | For Each o As T In Items |
| 135 | Yield o |
| 136 | Next |
| 137 | End Function |
| 138 | |
| 139 | Private Iterator Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator |
| 140 | Yield GetEnumerator() |
| 141 | End Function |
| 142 | End Structure |
| 143 | End Namespace |