11# Region "Microsoft.VisualBasic::0a08872e6ce0b4df20608165e1499b8a, Data_science\Mathematica\Math\Math\HashMaps\HashMap.vb"
22
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-
35- ' Code Statistics:
36-
37- ' Total Lines: 397
38- ' Code Lines: 261 (65.74%)
39- ' Comment Lines: 69 (17.38%)
40- ' - Xml Docs: 100.00%
41- '
42- ' Blank Lines: 67 (16.88%)
43- ' File Size: 14.32 KB
44-
45-
46- ' Module HashMap
47- '
48- ' Function: (+2 Overloads) HashAP, (+2 Overloads) HashBKDR, (+2 Overloads) HashCMyMap, (+2 Overloads) HashCodePair, (+2 Overloads) HashDEK
49- ' (+2 Overloads) HashDJB, (+2 Overloads) HashELF, (+2 Overloads) HashJS, (+2 Overloads) HashPJW, (+2 Overloads) HashRS
50- ' (+2 Overloads) HashSDBM, (+2 Overloads) HashTimeMap
51- '
52- '
53- ' /********************************************************************************/
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+
35+ ' Code Statistics:
36+
37+ ' Total Lines: 397
38+ ' Code Lines: 261 (65.74%)
39+ ' Comment Lines: 69 (17.38%)
40+ ' - Xml Docs: 100.00%
41+ '
42+ ' Blank Lines: 67 (16.88%)
43+ ' File Size: 14.32 KB
44+
45+
46+ ' Module HashMap
47+ '
48+ ' Function: (+2 Overloads) HashAP, (+2 Overloads) HashBKDR, (+2 Overloads) HashCMyMap, (+2 Overloads) HashCodePair, (+2 Overloads) HashDEK
49+ ' (+2 Overloads) HashDJB, (+2 Overloads) HashELF, (+2 Overloads) HashJS, (+2 Overloads) HashPJW, (+2 Overloads) HashRS
50+ ' (+2 Overloads) HashSDBM, (+2 Overloads) HashTimeMap
51+ '
52+ '
53+ ' /********************************************************************************/
5454
5555# End Region
5656
57+ Imports System.Runtime.CompilerServices
5758Imports UncheckedUInt64 = System.Numerics.BigInteger
5859
5960Namespace HashMaps
@@ -400,7 +401,19 @@ Namespace HashMaps
400401 ''' <param name="KeyByte"></param>
401402 ''' <param name="seed">种子质数。 31,33,37 。。。</param>
402403 ''' <returns></returns>
403- Public Function HashTimeMap(KeyByte() As Byte , seed As UInt32) As ULong
404+ Public Function HashTimeMap( ByRef KeyByte() As Byte , seed As UInt32) As ULong
405+ Return BitConverter.ToUInt64(HashTimeMapCheckSum(KeyByte, seed), 0 )
406+ End Function
407+
408+ ''' <summary>
409+ ''' 经典的Time算法。简单,高效。
410+ ''' Ngix使用的是 time31,Tokyo Cabinet使用的是 time37
411+ ''' 小写英文词汇适合33, 大小写混合使用65。time33比较适合的是英文词汇的hash.
412+ ''' </summary>
413+ ''' <param name="KeyByte"></param>
414+ ''' <param name="seed">种子质数。 31,33,37 。。。</param>
415+ ''' <returns></returns>
416+ Public Function HashTimeMapCheckSum( ByRef KeyByte() As Byte , seed As UInt32) As Byte ()
404417 Dim nHash As UncheckedUInt64 = 0
405418 Dim L As Int32 = KeyByte.Length - 1
406419 Dim I As Int32 = 0
@@ -410,7 +423,29 @@ Namespace HashMaps
410423 I += 1
411424 End While
412425
413- Return nHash
426+ Return nHash.ToByteArray
427+ End Function
428+
429+ <Extension>
430+ Public Function CalcHashCode(ints As IEnumerable( Of ULong)) As Byte ()
431+ Dim bytes As New List( Of Byte )
432+
433+ For Each i As ULong In ints
434+ Call bytes.AddRange(BitConverter.GetBytes(i))
435+ Next
436+
437+ Return HashTimeMapCheckSum(bytes.ToArray, seed:= 37 )
438+ End Function
439+
440+ <Extension>
441+ Public Function CalcHashCode(ints As IEnumerable( Of Integer )) As ULong
442+ Dim bytes As New List( Of Byte )
443+
444+ For Each i As Integer In ints
445+ Call bytes.AddRange(BitConverter.GetBytes(i))
446+ Next
447+
448+ Return HashTimeMap(bytes.ToArray, seed:= 37 )
414449 End Function
415450
416451 ''' <summary>
0 commit comments