
''' <summary>
''' Provides static methods for creating tuple objects.
''' </summary>
''' <remarks></remarks>
Public Module Tuple

    ''' <summary>
    ''' Creates a new 1-tuple, or singleton.
    ''' </summary>
    ''' <typeparam name="T1">The type of the only component of the tuple.</typeparam>
    ''' <param name="item1">The value of the only component of the tuple.</param>
    ''' <returns>A tuple whose value is (<paramref name="item1"/>).</returns>
    ''' <remarks></remarks>
    Public Function Create(Of T1)(ByVal item1 As T1) As Tuple(Of T1)
        Return New Tuple(Of T1)(item1)
    End Function

    ''' <summary>
    ''' Creates a new 2-tuple, or pair.
    ''' </summary>
    ''' <typeparam name="T1">The type of the first component of the tuple.</typeparam>
    ''' <typeparam name="T2">The type of the second component of the tuple.</typeparam>
    ''' <param name="item1">The value of the first component of the tuple.</param>
    ''' <param name="item2">The value of the second component of the tuple.</param>
    ''' <returns>A tuple whose value is (<paramref name="item1"/>, <paramref name="item2"/>).</returns>
    ''' <remarks></remarks>
    Public Function Create(Of T1, T2)(ByVal item1 As T1, ByVal item2 As T2) As Tuple(Of T1, T2)
        Return New Tuple(Of T1, T2)(item1, item2)
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer) As Integer
        Return (h1 << 5) + h1 ^ h2
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer, ByVal h3 As Integer) As Integer
        Return Tuple.CombineHashCodes(Tuple.CombineHashCodes(h1, h2), h3)
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer, ByVal h3 As Integer, ByVal h4 As Integer) As Integer
        Return Tuple.CombineHashCodes(Tuple.CombineHashCodes(h1, h2), Tuple.CombineHashCodes(h3, h4))
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer, ByVal h3 As Integer, _
                                     ByVal h4 As Integer, ByVal h5 As Integer) As Integer
        Return Tuple.CombineHashCodes(Tuple.CombineHashCodes(h1, h2, h3, h4), h5)
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer, ByVal h3 As Integer, _
                                     ByVal h4 As Integer, ByVal h5 As Integer, ByVal h6 As Integer) As Integer
        Return Tuple.CombineHashCodes(Tuple.CombineHashCodes(h1, h2, h3, h4), Tuple.CombineHashCodes(h5, h6))
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer, ByVal h3 As Integer, _
                                     ByVal h4 As Integer, ByVal h5 As Integer, ByVal h6 As Integer, _
                                     ByVal h7 As Integer) As Integer
        Return Tuple.CombineHashCodes(Tuple.CombineHashCodes(h1, h2, h3, h4), Tuple.CombineHashCodes(h5, h6, h7))
    End Function

    Friend Function CombineHashCodes(ByVal h1 As Integer, ByVal h2 As Integer, ByVal h3 As Integer, _
                                     ByVal h4 As Integer, ByVal h5 As Integer, ByVal h6 As Integer, _
                                     ByVal h7 As Integer, ByVal h8 As Integer) As Integer
        Return Tuple.CombineHashCodes(Tuple.CombineHashCodes(h1, h2, h3, h4), Tuple.CombineHashCodes(h5, h6, h7, h8))
    End Function

End Module