in reply to Re: mapping lists
in thread mapping lists

I'd like to make a minor tweak to my solution. There's a sixth parameter "size" for binary_search, which is the point at which it reverts to a linear search, and it's defaulted to 512. That means the small @F array will be done with a linear search, after all.

I set the size down and did one more optimization, as follows:

my $lo_pos = binary_search(0,$#F,$lo,\&reader,\@F,2); my $hi_pos = binary_search($lo_pos,$#F,$hi,\&reader,\@F,2);
I added a counter to the reader function and got the following output:
Did 6 probes for low Did 6 probes for high 32,33,34,35 Did 6 probes for low Did 7 probes for high 50,51,52,53,54,55,56,57,58,59,60,61,62,63,64
This is compared to a total of 78 probes the original way.