in reply to boolean IN(); function in perl like

If @a is sorted, you can use a binary search. It's very fast on long lists. For example, it does at most 14 compares if the array has 15,000 elements.
  • Comment on Re: boolean IN(); function in perl like

Replies are listed 'Best First'.
Re^2: boolean IN(); function in perl like
by Ovid (Cardinal) on Jan 14, 2005 at 21:23 UTC

      If you mean it should be a module, I know, I know.

      And no, I write assembler for the Varian72 for these folks.

        No, what I meant by "C" programmer was that your solution was something a C programmer would be likely to think up. Of course, an assembly programmer would likely think the same thing :)

        Cheers,
        Ovid

        New address of my CGI Course.

        If you mean it should be a module

        I think he meant you were proposing a solution that would feature faster performance at the expense of added complexity in both the code and the data structure. Programmers who think in Perl tend not to think that way unless performance becomes a user-noticeable problem (and sometimes not even then -- depending on the situation, we sometimes prefer to throw hardware at performance issues until they go away, rather than make code maintenance harder; obviously sometimes that isn't a good option; O(n!) for example will eat any amount of hardware and ask when the soup course is coming).