List::Search

List::Search is a Perl module for fast searching of sorted lists.
Download

List::Search Ranking & Summary

Advertisement

  • Rating:
  • License:
  • Perl Artistic License
  • Price:
  • FREE
  • Publisher Name:
  • Edmund von der Burg
  • Publisher web site:
  • http://search.cpan.org/~evdb/

List::Search Tags


List::Search Description

List::Search is a Perl module for fast searching of sorted lists. List::Search is a Perl module for fast searching of sorted lists.SYNOPSIS use List::Search qw( list_search nlist_search custom_list_search ); # Create a list to search my @list = sort qw( bravo charlie delta ); # Search for a value, returns the index of first match print list_search( 'alpha', @list ); # 0 print list_search( 'charlie', @list ); # 1 print list_search( 'zebra', @list ); # -1 # Search numerically my @numbers = sort { $a $b } ( 10, 20, 100, 200, ); print nlist_search( 20, @numbers ); # 2 # Search using some other comparison my $cmp_code = sub { lc( $_ ) cmp lc( $_ ) }; my @custom_list = sort { $cmp_code->( $a, $b ) } qw( FOO bar BAZ bundy ); print list_search_generic( $cmp_code, 'foo', @custom_list );This module lets you quickly search a sorted list. It will return the index of the first entry that matches, or if there is no exact matches then the first entry that is greater than the search key.For example in the list my @list = qw( bob dave fred ); searching for dave will return 1 as $list eq 'dave'. Searching for charles will also return 1 as dave is the first entry that is greater than charles.If there are none of the entries match then -1 is returned. You can either check for this or use it as an index to get the last values in the list. Whichever approach you choose will depend on what you are trying to do.The actual searching is done using a binary search which is very fast. Requirements: · Perl


List::Search Related Software