Is there a way to calculate and generate a unique identifier for a given range of Int32
numbers? e.g. see the example please:
var range1 = [a, b, c, d];
var unique1 = GenerateUnique(range1);
var range2 = [b, a, d, c];
var unique2 = GenerateUnique(range2);
// unique1 and unique2 should be equal. I mean:
var areEqual = unique1 == unique2; // should be true
var range3 = [a, b, c, d];
var unique3 = GenerateUnique(range3);
// unique1 and unique3 should be equal. I mean:
areEqual = unique1 == unique3; // should be true
var range4 = [a, b, c, e]; // it has not d, but has e. different array.
var unique4 = GenerateUnique(range4);
// unique1 and unique4 should NOT be equal. I mean:
areEqual = unique1 == unique4; // should NOT be true / should be false
private int /* or even string */ GenerateUnique(int[] range) {
// what would be the implementation of this method?
}
UPDATE:
1- The ranges doesn't have any duplicate members. So there wouldn't be a [1, 2, 3, 4, 4]
set. So, there is always [1, 2, 3, 4]
2- Array can be sorted. No problem.
3- The purpose: I have a huge number of items in DB. Sometimes, I need to generate a Word
document of them. And, I don't want to regenerate a previously generated document. That's it. Ranges are modifiable, so I want to regenerate a document for a certain range, if and only if an item got added/removed to/from range. NOTE: Changing database and saving a range's last-change is not an option.