microsoft-visualbasic-runtime/ComponentModel/Algorithm/base/SlideWindow/SlideWindow.vb

148 lines
4.9 KiB
VB.net
Raw Normal View History

2020-03-28 15:44:37 +08:00
#Region "Microsoft.VisualBasic::7a3156fb0868cd0be2c2da152b5023fc, Microsoft.VisualBasic.Core\ComponentModel\Algorithm\base\SlideWindow\SlideWindow.vb"
2019-07-13 23:56:14 +08:00
' Author:
'
' asuka (amethyst.asuka@gcmodeller.org)
' xie (genetics@smrucc.org)
' xieguigang (xie.guigang@live.com)
'
' Copyright (c) 2018 GPL3 Licensed
'
'
' GNU GENERAL PUBLIC LICENSE (GPL3)
'
'
' This program is free software: you can redistribute it and/or modify
' it under the terms of the GNU General Public License as published by
' the Free Software Foundation, either version 3 of the License, or
' (at your option) any later version.
'
' This program is distributed in the hope that it will be useful,
' but WITHOUT ANY WARRANTY; without even the implied warranty of
' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
' GNU General Public License for more details.
'
' You should have received a copy of the GNU General Public License
' along with this program. If not, see <http://www.gnu.org/licenses/>.
' /********************************************************************************/
' Summaries:
' Structure SlideWindow
'
' Properties: Index, Items, left, Length, right
'
' Function: GetEnumerator, GetEnumerator1, ToString
'
' Sub: Assign
'
'
' /********************************************************************************/
2018-08-02 20:14:48 +08:00
#End Region
Imports System.Runtime.CompilerServices
Imports Microsoft.VisualBasic.ComponentModel.Ranges.Model
Imports Microsoft.VisualBasic.Language
Imports Microsoft.VisualBasic.Serialization.JSON
Namespace ComponentModel.Algorithm.base
''' <summary>
''' A slide window data model.(滑窗操作的数据模型)
''' </summary>
''' <typeparam name="T"></typeparam>
''' <remarks></remarks>
Public Structure SlideWindow(Of T)
Implements IEnumerable(Of T), IAddressOf
Implements IGrouping(Of Integer, T)
Implements Value(Of T()).IValueOf
Implements IRange(Of Integer)
''' <summary>
''' The position of the current Windows in the Windows list.(在创建的滑窗的队列之中当前的窗口对象的位置)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public Property Index As Integer Implements IAddressOf.Address, IGrouping(Of Integer, T).Key
''' <summary>
''' The elements in this slide window.(这个划窗之中的元素的列表)
''' </summary>
''' <returns></returns>
Public Property Items As T() Implements Value(Of T()).IValueOf.Value
#Region "Index Range"
Default Public ReadOnly Property Item(index As Integer) As T
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
If index < 0 Then
2019-07-04 20:16:19 +08:00
Return Items(Length + index)
2018-08-02 20:14:48 +08:00
Else
2019-07-04 20:16:19 +08:00
Return Items(index)
2018-08-02 20:14:48 +08:00
End If
End Get
End Property
''' <summary>
''' The left start position of the current slide Windows segment on the original sequence.
''' (当前窗口在原始的序列之中的左端起始位点)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
2019-07-04 20:16:19 +08:00
Public Property left As Integer Implements IRange(Of Integer).Min
2018-08-02 20:14:48 +08:00
2019-07-04 20:16:19 +08:00
Public ReadOnly Property right As Integer Implements IRange(Of Integer).Max
2018-08-02 20:14:48 +08:00
<MethodImpl(MethodImplOptions.AggressiveInlining)>
Get
2019-07-04 20:16:19 +08:00
Return left + Length
2018-08-02 20:14:48 +08:00
End Get
End Property
#End Region
''' <summary>
''' The length of the slide window.(窗口长度)
''' </summary>
''' <value></value>
''' <returns></returns>
''' <remarks></remarks>
Public ReadOnly Property Length As Integer
2020-02-04 23:00:53 +08:00
<DebuggerStepThrough>
2018-08-02 20:14:48 +08:00
Get
If Items.IsNullOrEmpty Then
Return 0
Else
Return Items.Length
End If
End Get
End Property
2020-02-04 23:00:53 +08:00
<DebuggerStepThrough>
Private Sub Assign(address As Integer) Implements IAddress(Of Integer).Assign
2018-08-02 20:14:48 +08:00
Index = address
End Sub
Public Overrides Function ToString() As String
Return $"{Index} --> {Items.GetJson}"
End Function
2020-02-04 23:00:53 +08:00
<DebuggerStepThrough>
2018-08-02 20:14:48 +08:00
Public Iterator Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
For Each o As T In Items
Yield o
Next
End Function
2020-02-04 23:00:53 +08:00
<DebuggerStepThrough>
2018-08-02 20:14:48 +08:00
Private Iterator Function GetEnumerator1() As IEnumerator Implements IEnumerable.GetEnumerator
Yield GetEnumerator()
End Function
End Structure
End Namespace