in reply to Re: Search a hash for closest match
in thread Search a hash for closest match

Okay, I'll use a HoA instead I wasn't thinking about the data structure as I was hung up on thinking about how to make an efficient algorithm to do this. I was also thinking about doing a binary search as you suggested.

The range of positions is going to be quite large(between 1-250M for large chromosomes, 25 chromosomes) for the eQTL set but only 928,000 positions in total. My query list will be probably in the dozens at most. I will need to do a lookup for each item in my query list.

Replies are listed 'Best First'.
Re^3: Search a hash for closest match
by BrowserUk (Patriarch) on Nov 01, 2011 at 19:02 UTC

    Given small number of searches and the ~40k values per search, you may well find that a simple linear search using List::MoreUtils::firstidx() is more than adequate for your needs.

    Indeed, you may well find that as the linear search is coded in C, that it beats a binary search in Perl.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.