GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages


Manual Reference Pages  -  SEARCH::BINARY (3)

.ds Aq ’

NAME

Search::Binary -- generic binary search

CONTENTS

SYNOPSIS



  use Search::Binary;
  $pos = binary_search($min, $max, $val, $read, $handle, [$size]);



DESCRIPTION

binary_search implements a generic binary search algorithm returning the position of the first record whose index value is greater than or equal to $val. The search routine does not define any of the terms position, record or index value, but leaves their interpretation and implementation to the user supplied function &$read(). The only restriction is that positions must be integer scalars.

During the search the read function will be called with three arguments: the input parameters $handle and $val, and a position. If the position is not undef, the read function should read the first whole record starting at or after the position; otherwise, the read function should read the record immediately following the last record it read. The search algorithm will guarantee that the first call to the read function will not be with a position of undef. The read function needs to return a two element array consisting of the result of comparing $val with the index value of the read record and the position of the read record. The comparison value must be positive if $val is strictly greater than the index value of the read record, 0 if equal, and negative if strictly less. Furthermore, the returned position value must be greater than or equal to the position the read function was called with.

The input parameters $min and $max are positions and represents the extent of the search. Only records which begin at positions within this range (inclusive) will be searched. Moreover, $min must be the starting position of a record. If present $size is a difference between positions and determines when the algorithms switches to a sequential search. $val is an index value. The value of $handle is of no consequence to the binary search algorithm; it is merely passed as a convenience to the read function.

COPYRIGHT



  Copyright 1998, Erik Rantapaa



This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

Search for    or go to Top of page |  Section 3 |  Main Index


perl v5.20.3 BINARY (3) 2016-03-17

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with manServer 1.07.