dev-master
9999999-dev https://github.com/krichprollsch/file-binary-searchBinary Search in a file.
MIT
The Requires
- php >=5.3.0
by Pierre Tachoire
file search binary
Wallogit.com
2017 © Pedro Peláez
Binary Search in a file.
Binary search into sorted formatted file., (*1)
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');
phpunit
Files structure inspired by Geocoder from William Durand, (*5)
Binary Search in a file.
MIT
file search binary