Skip to content

Commit a006d3c

Browse files
committed
stdlib: improve comments
1 parent 5922aa8 commit a006d3c

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

stdlib/public/core/Hashing.swift

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ func _mixInt(_ value: Int) -> Int {
147147
#endif
148148
}
149149

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.
152152
///
153153
/// The `upperBound` must be positive and a power of 2.
154154
///
@@ -169,6 +169,9 @@ public // @testable
169169
func _squeezeHashValue(_ hashValue: Int, _ upperBound: Int) -> Int {
170170
_sanityCheck(_isPowerOf2(upperBound))
171171
let mixedHashValue = _mixInt(hashValue)
172+
173+
// As `upperBound` is a power of two we can do a bitwise-and to calculate
174+
// mixedHashValue % upperBound.
172175
return mixedHashValue & (upperBound &- 1)
173176
}
174177

0 commit comments

Comments
 (0)