Created
October 17, 2021 14:21
-
-
Save smosko/46b1b61c7fc48c0c42198b663d0f65bb to your computer and use it in GitHub Desktop.
Swift implementation of the String.hashCode() from Java / Android
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension String { | |
func hashCode() -> Int32 { | |
unicodeScalars.map { Int32($0.value) }.reduce(0) { 31 &* $0 &+ $1 } | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment