Is this hash unique?

I need to uniquely identify a pair of user identifiers Facebook. Here is how I do it:

NSString *firstId  = @"123456789";
NSString *secondId = @"987654321";

NSUInteger first_hash = [firstId hash];
NSUInteger second_hash = [secondId hash];

NSUInteger combinedHash = first_hash ^ second_hash;
NSUInteger reverseHash  = second_hash ^ first_hash;

NSLog(@"Combined hash %d\nReverse hash %d", combinedHash, reverseHash); // both are equal

Ok, now I know that regardless of the order in which the hashes are combined, I get the same value. It's good. But is this value unique? Or it is possible that a combination of identifiers 322233322, and 233322233will give the same value as that for combinedHash? If so, how to make a unique identifier for a pair of identifiers?

+4
source share
2 answers

ObjectiveC, , XOR-ing .
, , . 101 ^ 100 = 001
001 ^ 000 = 001
.

?
: , .
, , , , .
( , :))

edit, :
.
, ID .

+5

- , 1 ^ 1 == 0 ^ 0 1 ^ 0 = 0 ^ 1. , , , .

- , . , , .

1 .

+3

Source: https://habr.com/ru/post/1525920/


All Articles