如何获得两个二维数组之间的交集?
How to get the intersection between two bi-dimensional Arrays?
我想得到两个二维数组之间的交集,return它作为一个二维数组作为这里声明的函数:
Private Function GetIntersection(ByVal Array2D1 As String(,), ByVal Array2D2 As String(,)) As String(,)
Public Class Pair : Implements IEquatable(Of Pair) 'Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.
'the Pair values to compare
Public Report As String
Public Match As String
'Indicates whether the current object is equal to another object of the same type.
Public Function Equals1(p As Pair) As Boolean Implements IEquatable(Of Pair).Equals
Return Report = p.Report And Match = p.Match
End Function
'A hash code intended for efficient lookup in collections that are based on a hash table.
Public Overrides Function GetHashCode() As Integer
Dim hashReport = Report.GetHashCode()
Dim hashMatch = Match.GetHashCode()
Return hashReport Xor hashMatch
End Function
结束Class
Private Function GetIntersection(ByVal one As List(Of Pair), ByVal second As List(Of Pair)) As List(Of Pair)
Dim intersection As New List(Of Pair)
If second.Count = 0 Then
second = one
End If
intersection = one.Intersect(second).ToList
Return intersection
End Function
我想得到两个二维数组之间的交集,return它作为一个二维数组作为这里声明的函数:
Private Function GetIntersection(ByVal Array2D1 As String(,), ByVal Array2D2 As String(,)) As String(,)
Public Class Pair : Implements IEquatable(Of Pair) 'Defines a generalized method that a value type or class implements to create a type-specific method for determining equality of instances.
'the Pair values to compare
Public Report As String
Public Match As String
'Indicates whether the current object is equal to another object of the same type.
Public Function Equals1(p As Pair) As Boolean Implements IEquatable(Of Pair).Equals
Return Report = p.Report And Match = p.Match
End Function
'A hash code intended for efficient lookup in collections that are based on a hash table.
Public Overrides Function GetHashCode() As Integer
Dim hashReport = Report.GetHashCode()
Dim hashMatch = Match.GetHashCode()
Return hashReport Xor hashMatch
End Function
结束Class
Private Function GetIntersection(ByVal one As List(Of Pair), ByVal second As List(Of Pair)) As List(Of Pair)
Dim intersection As New List(Of Pair)
If second.Count = 0 Then
second = one
End If
intersection = one.Intersect(second).ToList
Return intersection
End Function