I have a web page which allows to select geographical areas. I expect than not more than 5000 areas are selected.
Each area has a code (9 characters long).
I want to load a collection of areas from DB and let the user edit it.
If a user has made any changes, I want to show the 'unsaved changes' message somewhere. In order to do it, I want to compare the original and the current version of the collection.
Is it possible to calculate a hash code of this collection and compare just hash codes? Order of elements is not important and should be ignored.
The collection is currently implemented in this way
function AreaHashTable(areaIdentifiers) {
//properties
this.hash = {};
this.addKeys(areaIdentifiers); }
AreaHashTable.prototype.getKeys = function () {
return this.hash; };
AreaHashTable.prototype.hasKey = function (key) {
if (this.getKeys().hasOwnProperty(key)) {
return true;
}
return false; };
AreaHashTable.prototype.addKey = function (gssCode) {
this.hash[gssCode] = gssCode;
};
AreaHashTable.prototype.addKeys = function (areaIdentifiers) {
var i;
for (i = 0; i < areaIdentifiers.length; i++) {
this.addKey(areaIdentifiers[i]);
} };
... etc
}