I have this function for hashing:
func djb2Hash(_ string: String) -> Int {
let unicodeScalars = string.unicodeScalars.map { $0.value }
return unicodeScalars.reduce(5381) {
($0 << 5) &+ $0 &+ Int($1)
}
}
djb2Hash("abc") // outputs 193485963
djb2Hash("bca") // outputs 193487083
I don't understand why the author used reduce(5381)
and don't really get the code from the closure that comes next. Can someone explain.
Thanks