BSearch - binary search
use lib '/proj/axaf/simul/lib/perl'; use BSearch;
my @foo = ( 1, 2, 3, 4, 5 );
my $match = bsearch ( 5, \@foo, sub { ${$_[0]} <=> ${$_[1]} } );
This module provides routines to perform binary searches upon arrays.
Perform a binary search on an ordered array of items. $key is a reference to the item that is searched for, $array_ref is a reference to the array to be searched, and $func_ref is a reference to a function which will compare the key to an array
element. This function should take as arguments two references; the first
will be $key_ref; the second will be a reference to an array element. It
should return 0 if there's a match, -1 if the key is less than the array element, and 1 if the key is greater than the array element. It returns a reference to the
matching element, or the undefined value if no match was found.
Diab Jerius ( djerius@cfa.harvard.edu )
$Id: BSearch.pm,v 1.1.1.1 1998/09/24 21:41:20 dj Exp $