in reply to The fastest way of searching a certain element in an array

I'd still check a map solution, just to be sure.

Also, your data is sorted, which means that a linear search on the data is not the most efficient algorithm. You should either implement a binary search, use an existing implementation, or keep your data unsorted.

----
: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: The fastest way of searching a certain element in an array
by dragonchild (Archbishop) on Apr 11, 2004 at 03:51 UTC
    The point is still made that when doing repeated searches on a datastore, one must consider what kind of store it is. Sortedness, what data it's storing, what kind of searching facilities already exist for it ... there is never a "One Right Answer"tm for any computing question (though there are many "Less Than Perfect"tm answers).

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Re: Re: The fastest way of searching a certain element in an array
by ccn (Vicar) on Apr 10, 2004 at 18:49 UTC
    No, @Array is not sorted.

      Oops, you're right. I was reading off @pos. Must pay more attention to code.

      ----
      : () { :|:& };:

      Note: All code is untested, unless otherwise stated