Skip to content

Commit 3618164

Browse files
committed
[stdlib] Add _mixForSynthesizedHashValue to stdlib
1 parent aef3d09 commit 3618164

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

stdlib/public/core/Hashing.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,15 @@ func _squeezeHashValue(_ hashValue: Int, _ upperBound: Int) -> Int {
175175
return mixedHashValue & (upperBound &- 1)
176176
}
177177

178+
/// Returns a new value that combines the two given hash values.
179+
///
180+
/// This function is used by synthesized implementations of `hashValue` to
181+
/// combine the hash values of individual `struct` fields and associated values
182+
/// of `enum`s. It is factored out into a standard library function so that the
183+
/// specific hashing logic can be refined without requiring major changes to the
184+
/// code that creates the synthesized AST nodes.
185+
@_transparent
186+
public // @testable
187+
func _mixForSynthesizedHashValue(_ oldValue: Int, _ nextValue: Int) -> Int {
188+
return 31 &* oldValue &+ nextValue
189+
}

0 commit comments

Comments
 (0)