Hello everyone,
I'm working on an AS3 game engine.
I have several objects which have names, and are stored in an internal class which combines the name, objects, and any related data, then stores each of these in a Vector.
Here is a quick example:
// Test.as
public class Test {
protected var namedData:Vector.<NamedData> = new Vector.<NamedData>();
public function Test() {}
public function Add(name:String, data:Object):void {
namedData.push(new NamedData(name, data));
}
}
internal class NamedData {
protected var name:String;
protected var data:Object;
public function NamedData(name:String, data:Object) {
this.name = name;
this.data = data;
}
}
with relevant accessors, get functions, etc.
Now, the reason for this post:
For get function I loop through each of the data, looking for a match to the name. When I find it, I return it. (There are proper things in place to prevent duplicate names getting added and what-not).
My question is:
Do you think a Hash Table would give me a significant enough performance boost that I should reconsider how I do these types of classes, so I could go from something like:
function Get(name:String):Object {
for each(var d:NamedData in namedData)
if(d.Name == name)
return d.Data;
}
to this:
function Get(name:String):Object {
if(hash[name])
return hash[name];
}
???
Thanks.