2017 © Pedro Peláez
 

library file-binary-search

Binary Search in a file.

image

ptachoire/file-binary-search

Binary Search in a file.

  • Monday, October 1, 2012
  • by krichprollsch
  • Repository
  • 1 Watchers
  • 1 Stars
  • 26 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 1 Open issues
  • 1 Versions
  • 53 % Grown

The README.md

FileBinarySearch

Binary search into sorted formatted file., (*1)

Build Status, (*2)

Usage

Usage sample :, (*3)

require_once( 'src/autoload.php');
$file = tempnam("/tmp", "sample_file_binary_search_");
file_put_contents($file, implode("\n", range(10,20,2)));

$fbs = new \FileBinarySearch\FileBinarySearch($file);

var_dump( $fbs->search(10));
/*
string(2) "10"
*/

var_dump( $fbs->search(14));
/*
string(2) "14"
*/

var_dump( $fbs->search(15));
/*
bool(false)
 */

var_dump( $fbs->search(25));
/*
bool(false)
*/

If you have formated lines, you can use your own comparaison method, (*4)

function mycompare( $tested_line, $searched_value ) {
    //returns < 0 if $tested_line < $searched_value
    //returns > 0 if $tested_line > $searched_value
    //returns 0 if $tested_line == $searched_value
}

$fbs = new \FileBinarySearch\FileBinarySearch($file, 'mycompare');

Unit Tests

phpunit

Thanks

Files structure inspired by Geocoder from William Durand, (*5)

The Versions

01/10 2012

dev-master

9999999-dev https://github.com/krichprollsch/file-binary-search

Binary Search in a file.

  Sources   Download

MIT

The Requires

  • php >=5.3.0

 

by Pierre Tachoire

file search binary