Skip to content

Commit

Permalink
code style improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Apr 11, 2022
1 parent cff98bb commit 5fc766d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
7 changes: 7 additions & 0 deletions Data_science/Graph/Model/Tree/KdTree/Analysis.vb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ Namespace KdTree
.FindNeighbors(k)
End Function

''' <summary>
''' the output keeps the same order as the given input <paramref name="data"/>
''' </summary>
''' <param name="data"></param>
''' <param name="k"></param>
''' <returns></returns>
<Extension>
Public Iterator Function FindNeighbors(data As IEnumerable(Of TagVector), Optional k As Integer = 30) As IEnumerable(Of (size As Integer, indices As Integer(), weights As Double()))
Dim allData As TagVector() = data.ToArray
Expand Down Expand Up @@ -133,6 +139,7 @@ Namespace KdTree

Dim index As Integer
Dim vector As Double()
Dim tag As String

Public ReadOnly Property size As Integer
Get
Expand Down
11 changes: 9 additions & 2 deletions Microsoft.VisualBasic.Core/src/Extensions/Security/Md5.vb
Original file line number Diff line number Diff line change
Expand Up @@ -142,16 +142,23 @@ Namespace SecurityString
''' in Java wrong).
''' Essentially, though, you'll want to do something like this:
'''
''' ```
''' Long a = md5[0] * 256 * md5[1] + 256 * 256 * md5[2] + 256 * 256 * 256 * md5[3];
''' Long b = md5[4] * 256 * md5[5] + 256 * 256 * md5[6] + 256 * 256 * 256 * md5[7];
''' Long result = a ^ b;
''' ```
'''
''' Note I have made no attempt To deal With endianness. If you just care about a consistent hash value,
''' though, endianness should Not matter.
''' </remarks>
<ExportAPI("As.Long")> <Extension>
<ExportAPI("As.Long")>
<Extension>
Public Function ToLong(bytes As Byte()) As Long
Dim md5 As Long() = bytes.Select(Function(x) CLng(x)).ToArray
Dim md5 As Long() = (From chunk As Byte()
In bytes.Split(4)
Let i32 As Integer = BitConverter.ToInt32(chunk, Scan0)
Select CLng(i32)).ToArray

Dim a As Long = md5(0) * 256 * md5(1) + 256 * 256 * md5(2) + 256 * 256 * 256 * md5(3)
Dim b As Long = md5(4) * 256 * md5(5) + 256 * 256 * md5(6) + 256 * 256 * 256 * md5(7)
Dim result As Long = a Xor b
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,8 @@ Public Module StringHelpers
''' </summary>
''' <param name="s$"></param>
''' <returns></returns>
<Extension> Public Function StringHashCode(s As String) As Long
<Extension>
Public Function StringHashCode(s As String) As Long
Dim hash& = 5381
Dim chars%() = s.Select(AddressOf Convert.ToInt32).ToArray

Expand Down

0 comments on commit 5fc766d

Please sign in to comment.