Writing a good hash function is tricky and Mike Ash talks a good talk on his blog about it. He goes on to talk about integer rotation and I was wondering how I would do something like this in Swift.
#define NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger))
#define NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (NSUINT_BIT - howmuch)))
- (NSUInteger)hash
{
return NSUINTROTATE([_firstName hash], NSUINT_BIT / 2) ^ [_lastName hash];
}
And how would you handle a third parameter?