improvements of the data api

This commit is contained in:
xieguigang 2020-01-04 14:34:29 +08:00
parent 28b43c38a4
commit bc6f3b0085
6 changed files with 87 additions and 49 deletions

View File

@ -222,12 +222,14 @@ Public Module VBDebugger
Return Nothing
End Function
<Extension> Public Sub __INFO_ECHO(msg$)
<Extension> Public Sub __INFO_ECHO(msg$, Optional silent As Boolean = False)
If Not Mute AndAlso m_level < DebuggerLevels.Warning Then
Dim head As String = $"INFOM {Now.ToString}"
Dim str As String = " " & msg
Call My.Log4VB.Print(head, str, ConsoleColor.White, MSG_TYPES.INF)
If Not silent Then
Call My.Log4VB.Print(head, str, ConsoleColor.White, MSG_TYPES.INF)
End If
#If DEBUG Then
Call Debug.WriteLine($"[{head}]{str}")
@ -252,8 +254,17 @@ Public Module VBDebugger
''' <param name="exception"></param>
'''
<MethodImpl(MethodImplOptions.AggressiveInlining)>
<Extension> Public Function PrintException(Of ex As Exception)(exception As ex, <CallerMemberName> Optional memberName$ = "") As Boolean
Return New Exception(memberName, exception).ToString.PrintException(memberName)
<Extension>
Public Function PrintException(Of ex As Exception)(exception As ex, <CallerMemberName> Optional memberName$ = "") As Boolean
Dim lines = New Exception(memberName, exception).ToString.LineTokens
Dim exceptions$() = Strings.Split(lines.First, "--->")
Dim formats = exceptions(0) & vbCrLf &
vbCrLf &
exceptions.Skip(1).JoinBy(vbCrLf) & vbCrLf &
vbCrLf &
lines.Skip(1).JoinBy(vbCrLf)
Return formats.PrintException(memberName)
End Function
''' <summary>

View File

@ -1,53 +1,53 @@
#Region "Microsoft.VisualBasic::96de3680f1c003d276cb4347540c5482, Microsoft.VisualBasic.Core\ComponentModel\System.Collections.Generic\KeyDictionary.vb"
' 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/>.
' 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:
' Summaries:
' Class HashTable
'
' Constructor: (+1 Overloads) Sub New
'
' Class Dictionary
'
' Constructor: (+3 Overloads) Sub New
'
' Function: Find, GetValueList, Have, Remove, SafeGetValue
' (+2 Overloads) TryGetValue
'
' Sub: Add, AddRange, InsertOrUpdate
'
' Operators: (+2 Overloads) -, ^, +, <=, >=
'
'
' /********************************************************************************/
' Class HashTable
'
' Constructor: (+1 Overloads) Sub New
'
' Class Dictionary
'
' Constructor: (+3 Overloads) Sub New
'
' Function: Find, GetValueList, Have, Remove, SafeGetValue
' (+2 Overloads) TryGetValue
'
' Sub: Add, AddRange, InsertOrUpdate
'
' Operators: (+2 Overloads) -, ^, +, <=, >=
'
'
' /********************************************************************************/
#End Region
@ -137,6 +137,7 @@ Namespace ComponentModel.Collection
End Set
End Property
<DebuggerStepThrough>
Sub New()
Call MyBase.New
End Sub
@ -151,10 +152,13 @@ Namespace ComponentModel.Collection
''' The System.Collections.Generic.IDictionary`2 whose elements are copied to the
''' new System.Collections.Generic.SortedDictionary`2.
''' </param>
'''
<DebuggerStepThrough>
Sub New(source As Dictionary(Of String, V))
Call MyBase.New(source)
End Sub
<DebuggerStepThrough>
Sub New(source As IEnumerable(Of V), Optional overridesDuplicateds As Boolean = False)
Call Me.New
@ -169,6 +173,7 @@ Namespace ComponentModel.Collection
End If
End Sub
<DebuggerStepThrough>
Public Function GetValueList() As List(Of V)
Return Values.AsList
End Function
@ -177,10 +182,13 @@ Namespace ComponentModel.Collection
''' Adds an element with the specified key and value into the System.Collections.Generic.SortedDictionary`2.
''' </summary>
''' <param name="item"></param>
'''
<DebuggerStepThrough>
Public Overloads Sub Add(item As V)
Call MyBase.Add(item.Key, item)
End Sub
<DebuggerStepThrough>
Public Sub AddRange(source As IEnumerable(Of V))
For Each x As V In source
Call MyBase.Add(x.Key, x)
@ -222,6 +230,7 @@ Namespace ComponentModel.Collection
''' <param name="item"></param>
''' <returns></returns>
<MethodImpl(MethodImplOptions.AggressiveInlining)>
<DebuggerStepThrough>
Public Function Have(item As V) As Boolean
Return MyBase.ContainsKey(item.Key)
End Function

View File

@ -754,6 +754,8 @@ Public Module KeyValuePairExtensions
''' <typeparam name="T">Unique identifier provider <see cref="INamedValue.Key"/></typeparam>
''' <param name="source"></param>
''' <returns></returns>
'''
<DebuggerStepThrough>
<Extension>
Public Function ToDictionary(Of T As INamedValue)(source As IEnumerable(Of T), Optional replaceOnDuplicate As Boolean = False) As Dictionary(Of T)
If source Is Nothing Then
@ -776,6 +778,7 @@ Public Module KeyValuePairExtensions
End If
End Function
<DebuggerStepThrough>
<Extension>
Private Function tableInternal(Of T As INamedValue)(source As IEnumerable(Of T),
ByRef currentKey$,

View File

@ -605,8 +605,7 @@ Public Module PathExtensions
<MethodImpl(MethodImplOptions.AggressiveInlining)>
<Extension>
Public Function DirectoryExists(DIR As String) As Boolean
Return Not String.IsNullOrEmpty(DIR) AndAlso
FileIO.FileSystem.DirectoryExists(DIR)
Return Not String.IsNullOrEmpty(DIR) AndAlso FileIO.FileSystem.DirectoryExists(DIR)
End Function
''' <summary>

View File

@ -275,6 +275,8 @@ Namespace Language
''' (这是一个安全的构造函数假若输入的参数为空值则只会创建一个空的列表而不会抛出错误)
''' </summary>
''' <param name="source">The collection whose elements are copied to the new list.</param>
'''
<DebuggerStepThrough>
Sub New(source As IEnumerable(Of T))
Call MyBase.New(If(source Is Nothing, {}, source.ToArray))
End Sub
@ -285,6 +287,8 @@ Namespace Language
''' to accommodate the number of elements copied.
''' </summary>
''' <param name="x">The collection whose elements are copied to the new list.</param>
'''
<DebuggerStepThrough>
Sub New(ParamArray x As T())
Call MyBase.New(If(x Is Nothing, {}, x))
End Sub
@ -293,6 +297,8 @@ Namespace Language
''' Initializes a new instance of the Microsoft VisualBasic language <see cref="List(Of T)"/> class
''' that is empty and has the default initial capacity.
''' </summary>
'''
<DebuggerStepThrough>
Public Sub New()
Call MyBase.New
End Sub
@ -302,10 +308,13 @@ Namespace Language
''' is empty and has the specified initial capacity.
''' </summary>
''' <param name="capacity">The number of elements that the new list can initially store.</param>
'''
<DebuggerStepThrough>
Public Sub New(capacity As Integer)
Call MyBase.New(capacity)
End Sub
<DebuggerStepThrough>
Public Sub New(size As Integer, fill As T)
For i As Integer = 0 To size - 1
Call Add(fill)

View File

@ -323,9 +323,12 @@ Namespace Language.Vectorization
#End Region
#Region "Constructor"
<DebuggerStepThrough>
Public Sub New()
End Sub
<DebuggerStepThrough>
Sub New(capacity%)
buffer = New T(capacity - 1) {}
End Sub
@ -334,15 +337,19 @@ Namespace Language.Vectorization
''' 构建一个新的向量对象这个向量对象只提供基本的数据存储和访问模型并没有提供高级的动态处理和模式解析的操作
''' </summary>
''' <param name="data"></param>
'''
<DebuggerStepThrough>
Sub New(data As IEnumerable(Of T))
buffer = data.ToArray
End Sub
#End Region
<DebuggerStepThrough>
Public Overrides Function ToString() As String
Return $"{buffer.Length} @ {GetType(T).FullName}"
End Function
<DebuggerStepThrough>
Public Overridable Iterator Function GetEnumerator() As IEnumerator(Of T) Implements IEnumerable(Of T).GetEnumerator
For Each element As T In buffer
Yield element