Reputation: 33
Following is the scanerio.
How can we generate a unique id (string/number), from a given unordered collection/set of objects (having their own uids).
How to make sure the generated id will always be the same even if the order of the objects changes in the collection/set.
I am working with groups of objects and each group needs a uid, to represent certain objects are present in it regardless of the order of the object, hope it makes sence, thanks in advance for your help.
Upvotes: 1
Views: 591
Reputation: 1410
Given that the number of possible objects are so limited, you can easily do this. Give each object a value which is a power of 2 (1,2,4,8,16, etc.) Then, for the collection, just sum the values of the objects in the collection. The result should fit in a 32 bit integer.
Upvotes: 1