To
avoid using loop searches like this I have used the idea of lookup tables
to help with locating something that I am looking for. I would have
basically two arrays:
lookup["a"] = 0
lookup["b"] = 1
lookup["c"] = 2
objectA.name = "a";
object[0] = objectA;
objectB.name = "b";
object[1] = objectB;
objectC.name = "c";
object[2] = objectC;
so if
I wand to find objectB I look for it by a given name. I just use "b"
here.
to get
objectB's index I just return:
i = lookup["b"];
if I
actually just want the object then I do:
o =
object[lookup["b"]];
I also
store the name with the object itself so that it can internally determine it's
position if needed.
I am
not certain that I have explained this well. I am also not certain this is
more efficient than looping through the array. For all I know that's what
JS does when you use arrays with named indexes... But this seems to work
really well for me. Any input would be appreciated
though.
M.
|
- Re: [Dynapi-Help] (style) Richard Bennett
- Re: [Dynapi-Help] (style) Raymond Smith
- [Dynapi-Help] (no subject) Leon Reinders
- [Dynapi-Help] (no subject) Chris Lemon
- Re: [Dynapi-Help] (no subject) Michael Pemberton
- Re: [Dynapi-Help] (no subject) Doug Melvin
- RE: [Dynapi-Help] (no subject) Chris Lemon
- [Dynapi-Help] (no subject) Terry Valladon
- Re: [Dynapi-Help] (no subject) Michael Pemberton
- [Dynapi-Help] (no subject) Doug Melvin
- [Dynapi-Help] (no subject) Matthew Alan Shirey
- [Dynapi-Help] (no subject) Chun Wah Chan
- [Dynapi-Help] (no subject) Michael Towers
- RE: [Dynapi-Help] (no subject) Eytan Heidingsfeld
- RE: [Dynapi-Help] (no subject) Michael Towers
- [Dynapi-Help] (no subject) Jan Wenda
- [Dynapi-Help] (no subject) [EMAIL PROTECTED]
- [Dynapi-Help] (no subject) Dave Edelhart
- Re: [Dynapi-Help] (no subject) CSS/NN Tom Wilcoxen
- RE: [Dynapi-Help] (no subject) Williams, Chris
- [Dynapi-Help] (no subject) Dougal Campbell