@@ -10,11 +10,11 @@ var HashingTestSuite = TestSuite("Hashing")
10
10
11
11
func checkHash(
12
12
for value: UInt64 ,
13
- withSeed seed: ( UInt64 , UInt64 ) ,
13
+ withSeed seed: UInt ,
14
14
expected: UInt64 ,
15
15
file: String = #file, line: UInt = #line
16
16
) {
17
- var hasher = Hasher ( _seed: seed)
17
+ var hasher = Hasher ( _seed: Int ( bitPattern : seed) )
18
18
hasher. _combine ( value)
19
19
let hash = hasher. finalize ( )
20
20
expectEqual (
@@ -23,50 +23,52 @@ func checkHash(
23
23
}
24
24
25
25
HashingTestSuite . test ( " Hasher/CustomKeys " ) {
26
- // This assumes Hasher implements SipHash-1-3.
27
- checkHash ( for: 0 , withSeed: ( 0 , 0 ) , expected: 0xbd60acb658c79e45 )
28
- checkHash ( for: 0 , withSeed: ( 0 , 1 ) , expected: 0x1ce32b0b44e61175 )
29
- checkHash ( for: 0 , withSeed: ( 1 , 0 ) , expected: 0x9c44b7c8df2ca74b )
30
- checkHash ( for: 0 , withSeed: ( 1 , 1 ) , expected: 0x9653ca0a3b455506 )
31
- checkHash ( for: 0 , withSeed: ( . max, . max) , expected: 0x3ab336a4895e4d36 )
32
-
33
- checkHash ( for: 1 , withSeed: ( 0 , 0 ) , expected: 0x1e9f734161d62dd9 )
34
- checkHash ( for: 1 , withSeed: ( 0 , 1 ) , expected: 0xb6fcf32d09f76cba )
35
- checkHash ( for: 1 , withSeed: ( 1 , 0 ) , expected: 0xacb556b13007504a )
36
- checkHash ( for: 1 , withSeed: ( 1 , 1 ) , expected: 0x7defec680db51d24 )
37
- checkHash ( for: 1 , withSeed: ( . max, . max) , expected: 0x212798441870ef6b )
38
-
39
- checkHash ( for: . max, withSeed: ( 0 , 0 ) , expected: 0x2f205be2fec8e38d )
40
- checkHash ( for: . max, withSeed: ( 0 , 1 ) , expected: 0x3ff7fa33381ecf7b )
41
- checkHash ( for: . max, withSeed: ( 1 , 0 ) , expected: 0x404afd8eb2c4b22a )
42
- checkHash ( for: . max, withSeed: ( 1 , 1 ) , expected: 0x855642d657c1bd46 )
43
- checkHash ( for: . max, withSeed: ( . max, . max) , expected: 0x5b16b7a8181980c2 )
26
+ // This assumes Hasher implements SipHash-1-3 and hashing is deterministic.
27
+ expectTrue ( Hasher . _isDeterministic)
28
+
29
+ checkHash ( for: 0 , withSeed: 0 , expected: 0xbd60acb658c79e45 )
30
+ checkHash ( for: 1 , withSeed: 0 , expected: 0x1e9f734161d62dd9 )
31
+ checkHash ( for: . max, withSeed: 0 , expected: 0x2f205be2fec8e38d )
32
+
33
+ checkHash ( for: 0 , withSeed: 1 , expected: 0x9c44b7c8df2ca74b )
34
+ checkHash ( for: 1 , withSeed: 1 , expected: 0xacb556b13007504a )
35
+ checkHash ( for: . max, withSeed: 1 , expected: 0x404afd8eb2c4b22a )
36
+
37
+ checkHash ( for: 0 , withSeed: 0xFFFFFFFF , expected: 0x47329159fe988221 )
38
+ checkHash ( for: 1 , withSeed: 0xFFFFFFFF , expected: 0xd7da861471fc35dc )
39
+ checkHash ( for: . max, withSeed: 0xFFFFFFFF , expected: 0xf6e3047fc114dbc0 )
40
+
41
+ #if !(arch(i386) || arch(arm))
42
+ checkHash ( for: 0 , withSeed: 0xFFFFFFFF_FFFFFFFF , expected: 0x8d0ea5ad8d6a55c7 )
43
+ checkHash ( for: 1 , withSeed: 0xFFFFFFFF_FFFFFFFF , expected: 0x2899f60d6b5bc847 )
44
+ checkHash ( for: . max, withSeed: 0xFFFFFFFF_FFFFFFFF , expected: 0xc4d7726fff5e65a0 )
45
+ #endif
44
46
}
45
47
46
48
HashingTestSuite . test ( " Hasher/DefaultKey " ) {
47
49
let value : UInt64 = 0x0102030405060708
48
50
49
51
let defaultHash = _hashValue ( for: value)
50
52
51
- let rawHash = value. _rawHashValue ( seed: Hasher . _seed )
53
+ let rawHash = value. _rawHashValue ( seed: 0 )
52
54
expectEqual ( rawHash, defaultHash)
53
55
54
- let oneShotHash = Hasher . _hash ( seed: Hasher . _seed , value)
56
+ let oneShotHash = Hasher . _hash ( seed: 0 , value)
55
57
expectEqual ( oneShotHash, defaultHash)
56
58
57
59
var defaultHasher = Hasher ( )
58
60
defaultHasher. _combine ( value)
59
61
expectEqual ( defaultHasher. finalize ( ) , defaultHash)
60
62
61
- var customHasher = Hasher ( _seed: Hasher . _seed )
63
+ var customHasher = Hasher ( _seed: 0 )
62
64
customHasher. _combine ( value)
63
65
expectEqual ( customHasher. finalize ( ) , defaultHash)
64
66
}
65
67
66
68
HashingTestSuite . test ( " Hashing/TopLevelHashing/UInt64 " ) {
67
69
func checkTopLevelHash(
68
70
for value: UInt64 ,
69
- seed: ( UInt64 , UInt64 ) ,
71
+ seed: Int ,
70
72
file: String = #file,
71
73
line: UInt = #line) {
72
74
var hasher = Hasher ( _seed: seed)
@@ -75,22 +77,20 @@ HashingTestSuite.test("Hashing/TopLevelHashing/UInt64") {
75
77
let actual = Hasher . _hash ( seed: seed, value)
76
78
expectEqual ( actual, expected, file: file, line: line)
77
79
}
78
- checkTopLevelHash ( for: 0 , seed: ( 0 , 0 ) )
79
- checkTopLevelHash ( for: 1 , seed: ( 0 , 0 ) )
80
- checkTopLevelHash ( for: 1 , seed: ( 1 , 0 ) )
81
- checkTopLevelHash ( for: 1 , seed: ( 1 , 1 ) )
82
- checkTopLevelHash ( for: 0x0102030405060708 , seed: ( 1 , 1 ) )
83
- checkTopLevelHash (
84
- for: 0x0102030405060708 ,
85
- seed: ( 0x0807060504030201 , 0x090a0b0c0d0e0f ) )
86
- checkTopLevelHash ( for: UInt64 . max, seed: ( 1 , 1 ) )
87
- checkTopLevelHash ( for: UInt64 . max, seed: ( UInt64 . max, UInt64 . max) )
80
+ checkTopLevelHash ( for: 0 , seed: 0 )
81
+ checkTopLevelHash ( for: 1 , seed: 0 )
82
+ checkTopLevelHash ( for: 0 , seed: 1 )
83
+ checkTopLevelHash ( for: 1 , seed: 1 )
84
+ checkTopLevelHash ( for: 0x0102030405060708 , seed: 1 )
85
+ checkTopLevelHash ( for: 0x0102030405060708 , seed: Int . max)
86
+ checkTopLevelHash ( for: UInt64 . max, seed: 1 )
87
+ checkTopLevelHash ( for: UInt64 . max, seed: Int . max)
88
88
}
89
89
90
90
HashingTestSuite . test ( " Hashing/TopLevelHashing/UInt " ) {
91
91
func checkTopLevelHash(
92
92
for value: UInt ,
93
- seed: ( UInt64 , UInt64 ) ,
93
+ seed: Int ,
94
94
file: String = #file,
95
95
line: UInt = #line) {
96
96
var hasher = Hasher ( _seed: seed)
@@ -99,25 +99,25 @@ HashingTestSuite.test("Hashing/TopLevelHashing/UInt") {
99
99
let actual = Hasher . _hash ( seed: seed, value)
100
100
expectEqual ( actual, expected, file: file, line: line)
101
101
}
102
- checkTopLevelHash ( for: 0 , seed: ( 0 , 0 ) )
103
- checkTopLevelHash ( for: 1 , seed: ( 0 , 0 ) )
104
- checkTopLevelHash ( for: 1 , seed: ( 1 , 0 ) )
105
- checkTopLevelHash ( for: 1 , seed: ( 1 , 1 ) )
102
+ checkTopLevelHash ( for: 0 , seed: 0 )
103
+ checkTopLevelHash ( for: 1 , seed: 0 )
104
+ checkTopLevelHash ( for: 0 , seed: 1 )
105
+ checkTopLevelHash ( for: 1 , seed: 1 )
106
106
checkTopLevelHash (
107
107
for: UInt ( truncatingIfNeeded: 0x0102030405060708 as UInt64 ) ,
108
- seed: ( 1 , 1 ) )
108
+ seed: 1 )
109
109
checkTopLevelHash (
110
110
for: UInt ( truncatingIfNeeded: 0x0102030405060708 as UInt64 ) ,
111
- seed: ( 0x8877665544332211 , 0x1122334455667788 ) )
112
- checkTopLevelHash ( for: UInt . max, seed: ( 1 , 1 ) )
113
- checkTopLevelHash ( for: UInt . max, seed: ( UInt64 . max, UInt64 . max ) )
111
+ seed: Int ( truncatingIfNeeded : 0x8877665544332211 as UInt64 ) )
112
+ checkTopLevelHash ( for: UInt . max, seed: 1 )
113
+ checkTopLevelHash ( for: UInt . max, seed: Int . max)
114
114
}
115
115
116
116
HashingTestSuite . test ( " Hashing/TopLevelHashing/PartialUInt64 " ) {
117
117
func checkTopLevelHash(
118
118
for value: UInt64 ,
119
119
count: Int ,
120
- seed: ( UInt64 , UInt64 ) ,
120
+ seed: Int ,
121
121
file: String = #file,
122
122
line: UInt = #line) {
123
123
var hasher = Hasher ( _seed: seed)
@@ -131,11 +131,12 @@ HashingTestSuite.test("Hashing/TopLevelHashing/PartialUInt64") {
131
131
file: file,
132
132
line: line)
133
133
}
134
- for seed : ( UInt64 , UInt64 ) in [
135
- ( 0 , 0 ) ,
136
- ( 1 , 0 ) ,
137
- ( 1 , 1 ) ,
138
- ( 0x1827364554637281 , 0xf9e8d7c6b5a49382 )
134
+ for seed : Int in [
135
+ 0 ,
136
+ 1 ,
137
+ 2 ,
138
+ Int ( truncatingIfNeeded: 0x1827364554637281 as UInt64 ) ,
139
+ Int ( truncatingIfNeeded: 0xf9e8d7c6b5a49382 as UInt64 )
139
140
] {
140
141
for count in 1 ..< 8 {
141
142
checkTopLevelHash ( for: 0 , count: count, seed: seed)
@@ -153,7 +154,7 @@ HashingTestSuite.test("Hashing/TopLevelHashing/PartialUInt64") {
153
154
HashingTestSuite . test ( " Hashing/TopLevelHashing/UnsafeRawBufferPointer " ) {
154
155
func checkTopLevelHash(
155
156
for buffer: [ UInt8 ] ,
156
- seed: ( UInt64 , UInt64 ) ,
157
+ seed: Int ,
157
158
file: String = #file,
158
159
line: UInt = #line) {
159
160
var hasher = Hasher ( _seed: seed)
@@ -171,11 +172,12 @@ HashingTestSuite.test("Hashing/TopLevelHashing/UnsafeRawBufferPointer") {
171
172
file: file,
172
173
line: line)
173
174
}
174
- for seed : ( UInt64 , UInt64 ) in [
175
- ( 0 , 0 ) ,
176
- ( 1 , 0 ) ,
177
- ( 1 , 1 ) ,
178
- ( 0x1827364554637281 , 0xf9e8d7c6b5a49382 )
175
+ for seed : Int in [
176
+ 0 ,
177
+ 1 ,
178
+ 2 ,
179
+ Int ( truncatingIfNeeded: 0x1827364554637281 as UInt64 ) ,
180
+ Int ( truncatingIfNeeded: 0xf9e8d7c6b5a49382 as UInt64 )
179
181
] {
180
182
var zeros : [ UInt8 ] = [ ]
181
183
var integers : [ UInt8 ] = [ ]
0 commit comments