|
-
Retired SCORM Guru
Fast array searching
I'm building an AS cache for SCORM data that stores info in a multidimensional array: [element name][element value].
The normal method to search this would be something like this:
code:
for (var i:Number=0; i<array.length; i++) {
if (array[i][0] == "someelementname") {
return array[i];
break;
}
}
Q1: Is there a faster / more efficient way to search the array?
Q2: If I'm going to add a 3rd property, a bit indicating whether or not the cache element has been committed back to the LMS or not, am I better off creating a class of objects or classes (e.g. write a cmi data element class: array[1] = new DataElement(score,200,0)), rather than using a multidimensional array?
The goal of this is to be efficient to eliminate lag between requesting data from the SCORM API and to prevent multiple SCORM API calls from being fired in a row by a developer, because ExternalInterface occasionally hiccups if that happens.
"What really bugs me is that my mom had the audacity to call Flash Kit a bunch of 'inept jack-asses'." - sk8Krog
...and now I have tape all over my face.
-
Señor Member
A1: my only thought is to have the elements following some logical naming system or order, so you can find it immediately using an equation of sorts. you could also try nested arrays
var nest:Object = new Object()
nest.someelementname = 6 //a number representing the index of the element name in the array
nest.someotherelementname = 3
then to reference and return it:
return array[nest.someelementname]
I don't know if this is any more efficient for your purposes, but it could work under certain circumstances I think.
A2: I don't know about that one, sorry.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|