I never liked searches, I remember doing an address book application in the mid 80's and routines for finding names in a big list were a pain. But I found if you are looking for efficiency sort your array first if possible. Now this really only applies if your data is in a format that this can work with. For my names db then, I would sort my list by surname on entry so the list was always in alphabetical order. Than when give a name you I would go the half way point and if the $string ascii values were less than the half way point go back half way. And so on homing in on the name. I found this achieved quick results. But it relies on the dataset being easily sortable.
This was in pascal and assembler and I have never really had to do anything since on the same scale because most datasets I work on now are coming from a Database Server which uses SQL to process the searches on that level. But I would think if the data is large enough and your searches happen often enough, you could build an index to use that you could than pull the values you need out of. Avoiding the overhead on the searches but adding the overhead on the data entry.
In reply to Re: finding index number in an array
by Ninthwave
in thread finding index number in an array
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |