I want to create a unique id from 3 input numbers. I don't care what the output is, just as long as it is unique. The input numbers are:
NSNumber num
NSUInteger hash
int i
The output should be:
unsigned int id
I don't care about losing precision from any of the input numbers, so I am thinking about calculating the id as:
id = (unsigned int)num + (unsigned int)hash + (unsigned int)i
But there are two problems that I see:
What happens at integer overflow
I'm having problems finding documentation about what happens at integer overflow in Objective-C.
The best source I have found is this article that says that the result is undefined: http://www.sicpers.info/2013/01/what-happens-when-you-add-one-to-an-integer/
That's not good. I wouldn't mind it starting from 0 again, but undefined is not a unique id.
How casting to unsigned int is implemented
I haven't found any information about how casting to unsigned int is implemented. Just interpreting the existing bits as an unsigned int would work fine for me. But casting wouldn't work as intended for me if the result is ever undefined or something like that.
I don't know what the best way forward is.
How should I calculate a unique id that is an unsigned int from various other number types?