I
IamIan
I'm using an array to store map features (name, lat, lon, caption,
etc), from which the user can then select an individual feature. The
problem is that when thousands of features are stored in the array,
looping over the entire array looking for a match is SLOW.
So I'm running a hash in parallel, where every time a feature is
pushed onto the array it's name is also added to the hash as an
identical key value pair. I then check if the key is defined in the
hash, and if it is, I want to use that feature's values from the
array. Problem is, I don't know the index number in the array for this
feature. Is there a way to look this up without looping over it, by
matching values between the array and hash?
Eg:
featureArray = new Array();
featureHash = new Object();
//assume lots of features pushed
featureArray.push({name:name, lat:lat, lon:lon, caption:caption});
featureHash[name] = name;
//more features pushed
function useSelectedFeature (name) {
if (featureHash[name] != undefined) {
//match featureArray.name to featureHash[name]
//use matched featureArray values
}
}
Thanks.
etc), from which the user can then select an individual feature. The
problem is that when thousands of features are stored in the array,
looping over the entire array looking for a match is SLOW.
So I'm running a hash in parallel, where every time a feature is
pushed onto the array it's name is also added to the hash as an
identical key value pair. I then check if the key is defined in the
hash, and if it is, I want to use that feature's values from the
array. Problem is, I don't know the index number in the array for this
feature. Is there a way to look this up without looping over it, by
matching values between the array and hash?
Eg:
featureArray = new Array();
featureHash = new Object();
//assume lots of features pushed
featureArray.push({name:name, lat:lat, lon:lon, caption:caption});
featureHash[name] = name;
//more features pushed
function useSelectedFeature (name) {
if (featureHash[name] != undefined) {
//match featureArray.name to featureHash[name]
//use matched featureArray values
}
}
Thanks.