File tree Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Expand file tree Collapse file tree 1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -147,8 +147,8 @@ func _mixInt(_ value: Int) -> Int {
147
147
#endif
148
148
}
149
149
150
- /// Given a hash value, returns an integer value between 0 and `upperBound`
151
- /// that corresponds to a hash value.
150
+ /// Given a hash value, returns an integer value in the range of
151
+ /// 0..<`upperBound` that corresponds to a hash value.
152
152
///
153
153
/// The `upperBound` must be positive and a power of 2.
154
154
///
@@ -169,6 +169,9 @@ public // @testable
169
169
func _squeezeHashValue( _ hashValue: Int , _ upperBound: Int ) -> Int {
170
170
_sanityCheck ( _isPowerOf2 ( upperBound) )
171
171
let mixedHashValue = _mixInt ( hashValue)
172
+
173
+ // As `upperBound` is a power of two we can do a bitwise-and to calculate
174
+ // mixedHashValue % upperBound.
172
175
return mixedHashValue & ( upperBound &- 1 )
173
176
}
174
177
You can’t perform that action at this time.
0 commit comments