| 1 | #Region "Microsoft.VisualBasic::f93b38a23bf677301f69723d2d1a27f1, Microsoft.VisualBasic.Core\ComponentModel\DataStructures\Set\StringSet.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 StringSet |
| 35 | ' |
| 36 | ' Constructor: (+2 Overloads) Sub New |
| 37 | ' Operators: -, (+2 Overloads) Or |
| 38 | ' |
| 39 | ' |
| 40 | ' /********************************************************************************/ |
| 41 | |
| 42 | #End Region |
| 43 | |
| 44 | Imports System.Runtime.CompilerServices |
| 45 | Imports Microsoft.VisualBasic.Linq |
| 46 | |
| 47 | Namespace ComponentModel.DataStructures |
| 48 | |
| 49 | ''' <summary> |
| 50 | ''' A string set collection object. |
| 51 | ''' </summary> |
| 52 | Public Class StringSet : Inherits [Set] |
| 53 | |
| 54 | ''' <summary> |
| 55 | ''' |
| 56 | ''' </summary> |
| 57 | ''' <param name="strings"></param> |
| 58 | ''' <param name="caseSensitive"> |
| 59 | ''' String comparision should be in case sensitive mode? By default is yes. |
| 60 | ''' </param> |
| 61 | Sub New(strings As IEnumerable(Of String), Optional caseSensitive As CompareMethod = CompareMethod.Binary) |
| 62 | Call MyBase.New |
| 63 | |
| 64 | Dim compare As StringComparison = caseSensitive.GetCompareType |
| 65 | |
| 66 | MyBase._equals = Function(s1, s2) |
| 67 | Return String.Equals(s1, s2, compare) |
| 68 | End Function |
| 69 | MyBase._members = New [Set](strings, MyBase._equals)._members |
| 70 | End Sub |
| 71 | |
| 72 | Friend Sub New([set] As [Set]) |
| 73 | Call MyBase.New |
| 74 | |
| 75 | MyBase._members = [set]._members |
| 76 | MyBase._equals = [set]._equals |
| 77 | End Sub |
| 78 | |
| 79 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 80 | Public Overloads Shared Operator Or(s1 As StringSet, s2 As IEnumerable(Of String)) As StringSet |
| 81 | Return New StringSet(DirectCast(s1, [Set]) Or New [Set](s2, s1._equals)) |
| 82 | End Operator |
| 83 | |
| 84 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 85 | Public Overloads Shared Narrowing Operator CType(s As StringSet) As String() |
| 86 | Return s.ToArray(Of String) |
| 87 | End Operator |
| 88 | |
| 89 | ''' <summary> |
| 90 | ''' Removes all of the <paramref name="s2"/> from <see cref="StringSet"/> <paramref name="s1"/> |
| 91 | ''' </summary> |
| 92 | ''' <param name="s1"></param> |
| 93 | ''' <param name="s2"></param> |
| 94 | ''' <returns></returns> |
| 95 | <MethodImpl(MethodImplOptions.AggressiveInlining)> |
| 96 | Public Overloads Shared Operator -(s1 As [StringSet], s2 As IEnumerable(Of String)) As StringSet |
| 97 | Return New StringSet(s1 - s2.AsSet) |
| 98 | End Operator |
| 99 | End Class |
| 100 | End Namespace |