Swift Hashing algorithm using bit shifting to avoid collisions

Viewed 216

Given a Person struct that has a name and surname string properties I would like to write an hashing algorithm that is efficient and avoids collisions for persons with interchangeable names and surnames (Lara Ray and Ray Lara for example.).

I already know to stir away from string concatenation in Swift, so Ideally I am thinking at XORing the 2 variables and bit shifting one of them to solve the interchangeable problem. Is there anything wrong with this?

struct Person {
    let name: String
    let surname: String

    var hashValue: Int {
        return surname.hashValue << 1 ^ name.hashValue
    }
}
1 Answers
Related