Пример #1
0
 public function __construct(FileInterface $file, TableSchemaInterface $tableSchema, IndexSchema $indexPage = null, $forkRate = 33)
 {
     $keyLength = 0;
     foreach ($indexPage->getColumns() as $columnId) {
         /* @var $columnPage ColumnSchema */
         $columnPage = $tableSchema->getColumn($columnId);
         assert(!is_null($columnPage));
         $keyLength += $columnPage->getCellSize();
     }
     if ($keyLength < 4) {
         $keyLength = 4;
     }
     if (!is_numeric($forkRate)) {
         throw new \ErrorException("Forkrate has to specified as integer!");
     }
     $forkRate = (int) $forkRate;
     $this->file = $file;
     $this->setKeyLength($keyLength);
     $this->forkRate = $forkRate;
     $this->tableSchema = $tableSchema;
     $this->indexPage = $indexPage;
     // if file is empty, initialize it
     if ($file->getLength() <= 1) {
         $file->setData(str_pad("", $keyLength * 8, ""));
         $rootNode = new BTreeNodePage();
         $rootNode->setKeyLength($keyLength);
         $rootNode->setForkRate($this->forkRate);
         // make sure root-reference is in index 1, not 0.
         // that way we can use reference 0 as 'not defined'/'not used'
         $this->setRootReference(1);
         $this->writeNode($rootNode, 1);
     }
 }