Ejemplo n.º 1
0
 * Index in a plain text file example
 *
 * The example shows how to use a plain text file with a defined index in each
 * line.
 * 
 * @author    Markus Malkusch <*****@*****.**>
 * @link      https://github.com/malkusch/php-index
 */
use malkusch\index\FixedSizeIndex;
use malkusch\index\IOIndexException;
use malkusch\index\ReadDataIndexException;
// Include the autoloader
require_once __DIR__ . "/../../../autoloader/autoloader.php";
try {
    // Define the index
    $index = new FixedSizeIndex(__DIR__ . "/index.txt", 0, 8);
    // Search the data for the key 10077777
    $data = $index->search(10077777);
    if ($data != null) {
        echo $data->getData(), "\n";
    } else {
        echo "Didn't find key 10020500\n";
    }
    // Search the data for the nonexistend key 12345.
    $data = $index->search(12345);
    if ($data != null) {
        echo $data->getData(), "\n";
    } else {
        echo "Didn't find key 12345\n";
    }
} catch (IOIndexException $e) {
Ejemplo n.º 2
0
 /**
  * Tests getLineLength()
  * 
  * @dataProvider provideTestGetLineLength
  * @see FixedSizeIndex::getLineLength()
  */
 public function testGetLineLength($expectedLineLength, $file)
 {
     $index = new index\FixedSizeIndex($file, 0, 1);
     $this->assertEquals($expectedLineLength, $index->getLineLength());
 }